aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSantiago Pastorino <santiago@wyeworks.com>2014-11-28 11:26:28 -0200
committerSantiago Pastorino <santiago@wyeworks.com>2014-11-28 11:26:28 -0200
commit1b1f4038eaff1b833b177b8795d28a30e3ca66ec (patch)
treee1c811be2bd6686b8da2117f582d9353cf652e52
parent2cdd229fc2a3848cf7d77ccb718544594e0373eb (diff)
parent6405a03c1303c4c2da7029cf9199bd17451fec4d (diff)
downloadrails-1b1f4038eaff1b833b177b8795d28a30e3ca66ec.tar.gz
rails-1b1f4038eaff1b833b177b8795d28a30e3ca66ec.tar.bz2
rails-1b1f4038eaff1b833b177b8795d28a30e3ca66ec.zip
Merge pull request #17811 from mrnugget/fixes_nested_association_preloading
Adds preloaded_records method to NullPreloader - fixes #16070
-rw-r--r--activerecord/lib/active_record/associations/preloader.rb1
-rw-r--r--activerecord/test/cases/associations/eager_test.rb8
2 files changed, 9 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/associations/preloader.rb b/activerecord/lib/active_record/associations/preloader.rb
index 46bccbf15a..4358f3b581 100644
--- a/activerecord/lib/active_record/associations/preloader.rb
+++ b/activerecord/lib/active_record/associations/preloader.rb
@@ -178,6 +178,7 @@ module ActiveRecord
class NullPreloader
def self.new(klass, owners, reflection, preload_scope); self; end
def self.run(preloader); end
+ def self.preloaded_records; []; end
end
def preloader_for(reflection, owners, rhs_klass)
diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb
index dd4f530791..f968a34886 100644
--- a/activerecord/test/cases/associations/eager_test.rb
+++ b/activerecord/test/cases/associations/eager_test.rb
@@ -270,6 +270,14 @@ class EagerAssociationTest < ActiveRecord::TestCase
end
end
+ def test_three_level_nested_preloading_does_not_raise_exception_when_association_does_not_exist
+ post_id = Comment.where(author_id: nil).where.not(post_id: nil).first.post_id
+
+ assert_nothing_raised do
+ Post.preload(:comments => [{:author => :essays}]).find(post_id)
+ end
+ end
+
def test_nested_loading_through_has_one_association
aa = AuthorAddress.all.merge!(:includes => {:author => :posts}).find(author_addresses(:david_address).id)
assert_equal aa.author.posts.count, aa.author.posts.length