Skip to content

Commit

Permalink
Test that tactical eager loading uses association from subclass when …
Browse files Browse the repository at this point in the history
…eager loading

It already worked this way, but it's better to have specs to
confirm the behavior to protect against regressions.
  • Loading branch information
jeremyevans committed Jun 22, 2024
1 parent 68279d0 commit e55fe96
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions spec/extensions/tactical_eager_loading_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,16 @@ class ::TacticalEagerLoadingModel < Sequel::Model(:t)
objs[0].associations.keys.must_equal [:parent]
objs[1].associations.keys.must_equal [:parent]

c.many_to_one :parent, :class=>@c, :key=>:parent_id
c.many_to_one :parent, :class=>@c, :key=>:parent_id, :conditions=>{:x=>1}
objs = @c.dataset.with_row_proc(proc{|r| (r[:parent_id] == 101 ? c : @c).call(r)}).all{|x| x.parent if x.is_a?(c)}
sql_match('SELECT * FROM t', 'SELECT * FROM t WHERE (t.id IN (101))')
sql_match('SELECT * FROM t', 'SELECT * FROM t WHERE ((x = 1) AND (t.id IN (101)))')
objs[0].associations.keys.must_equal [:parent]
objs[1].associations.keys.must_equal []

objs = @c.dataset.with_row_proc(proc{|r| (r[:parent_id] == 101 ? c : @c).call(r)}).all{|x| x.parent if !x.is_a?(c)}
sql_match('SELECT * FROM t', 'SELECT * FROM t WHERE (t.id IN (102))')
objs[0].associations.keys.must_equal []
objs[1].associations.keys.must_equal [:parent]
end

it "association getter methods should not eagerly load the association if an instance is frozen" do
Expand Down

0 comments on commit e55fe96

Please sign in to comment.