Skip to content

Commit 1b1f403

Browse files
committed
Merge pull request rails#17811 from mrnugget/fixes_nested_association_preloading
Adds preloaded_records method to NullPreloader - fixes rails#16070
2 parents 2cdd229 + 6405a03 commit 1b1f403

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

activerecord/lib/active_record/associations/preloader.rb

+1
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ def preloaded_records
178178
class NullPreloader
179179
def self.new(klass, owners, reflection, preload_scope); self; end
180180
def self.run(preloader); end
181+
def self.preloaded_records; []; end
181182
end
182183

183184
def preloader_for(reflection, owners, rhs_klass)

activerecord/test/cases/associations/eager_test.rb

+8
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,14 @@ def test_nested_loading_does_not_raise_exception_when_association_does_not_exist
270270
end
271271
end
272272

273+
def test_three_level_nested_preloading_does_not_raise_exception_when_association_does_not_exist
274+
post_id = Comment.where(author_id: nil).where.not(post_id: nil).first.post_id
275+
276+
assert_nothing_raised do
277+
Post.preload(:comments => [{:author => :essays}]).find(post_id)
278+
end
279+
end
280+
273281
def test_nested_loading_through_has_one_association
274282
aa = AuthorAddress.all.merge!(:includes => {:author => :posts}).find(author_addresses(:david_address).id)
275283
assert_equal aa.author.posts.count, aa.author.posts.length

0 commit comments

Comments
 (0)