From e55fe96f676138a67e24e0c4a9ef5025f176529b Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Sat, 22 Jun 2024 08:29:32 -0700 Subject: [PATCH] Test that tactical eager loading uses association from subclass when eager loading It already worked this way, but it's better to have specs to confirm the behavior to protect against regressions. --- spec/extensions/tactical_eager_loading_spec.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/spec/extensions/tactical_eager_loading_spec.rb b/spec/extensions/tactical_eager_loading_spec.rb index c99f46f13..19be47068 100644 --- a/spec/extensions/tactical_eager_loading_spec.rb +++ b/spec/extensions/tactical_eager_loading_spec.rb @@ -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