diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-01-01 14:14:45 -0200 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-01-01 14:14:45 -0200 |
commit | b94e2dd82c3c69d923c59842b8703856a715230c (patch) | |
tree | cdc7181252921c0c1ed57b47e7cc3f56a425e7b9 | |
parent | e015f4e2e3e962a3713f40e91aa049d47ed7c7f2 (diff) | |
parent | bb17c3b2105da30ef3260c3b489da85e4865eaa5 (diff) | |
download | rails-b94e2dd82c3c69d923c59842b8703856a715230c.tar.gz rails-b94e2dd82c3c69d923c59842b8703856a715230c.tar.bz2 rails-b94e2dd82c3c69d923c59842b8703856a715230c.zip |
Merge pull request #13550 from vipulnsward/13437-fix
Fix for #13437
Conflicts:
activerecord/CHANGELOG.md
-rw-r--r-- | activerecord/CHANGELOG.md | 7 | ||||
-rw-r--r-- | activerecord/lib/active_record/associations/preloader.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/associations/cascaded_eager_loading_test.rb | 14 |
3 files changed, 22 insertions, 1 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 4fdeae70d2..b5d3420dd7 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,10 @@ +* Fixed regression on preload/includes with multiple arguments failing in certain conditions, + raising a NoMethodError internally by calling `reflect_on_association` for `NilClass:Class`. + + Fixes #13437. + + *Vipul A M*, *khustochka* + * Add the ability to nullify the `enum` column. Example: diff --git a/activerecord/lib/active_record/associations/preloader.rb b/activerecord/lib/active_record/associations/preloader.rb index 2393667ac8..83637a0409 100644 --- a/activerecord/lib/active_record/associations/preloader.rb +++ b/activerecord/lib/active_record/associations/preloader.rb @@ -183,7 +183,7 @@ module ActiveRecord def run(preloader); end def preloaded_records - owners.flat_map { |owner| owner.read_attribute reflection.name } + owners.flat_map { |owner| owner.association(reflection.name).target } end end diff --git a/activerecord/test/cases/associations/cascaded_eager_loading_test.rb b/activerecord/test/cases/associations/cascaded_eager_loading_test.rb index 811d91f849..904d85266e 100644 --- a/activerecord/test/cases/associations/cascaded_eager_loading_test.rb +++ b/activerecord/test/cases/associations/cascaded_eager_loading_test.rb @@ -174,4 +174,18 @@ class CascadedEagerLoadingTest < ActiveRecord::TestCase sink = Vertex.all.merge!(:includes=>{:sources=>{:sources=>{:sources=>:sources}}}, :order => 'vertices.id DESC').first assert_equal vertices(:vertex_1), assert_no_queries { sink.sources.first.sources.first.sources.first.sources.first } end + + def test_eager_association_loading_with_cascaded_interdependent_one_level_and_two_levels + authors_relation = Author.all.merge!(:includes => [:comments, {:posts => :categorizations}], :order => "authors.id") + assert_nothing_raised do + authors_relation.to_a + end + authors = authors_relation.to_a + assert_equal 3, authors.size + assert_equal 10, authors[0].comments.size + assert_equal 1, authors[1].comments.size + assert_equal 5, authors[0].posts.size + assert_equal 3, authors[1].posts.size + assert_equal 3, authors[0].posts.collect { |post| post.categorizations.size }.inject(0) { |sum, i| sum+i } + end end |