Permalink
Browse files

Merge pull request #13550 from vipulnsward/13437-fix

Fix for #13437

Conflicts:
	activerecord/CHANGELOG.md
  • Loading branch information...
rafaelfranca committed Jan 1, 2014
2 parents e015f4e + bb17c3b commit b94e2dd82c3c69d923c59842b8703856a715230c
@@ -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:
@@ -183,7 +183,7 @@ def initialize(klass, owners, reflection, preload_scope)
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
@@ -174,4 +174,18 @@ def test_eager_association_loading_with_recursive_cascading_four_levels_has_and_
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

0 comments on commit b94e2dd

Please sign in to comment.