Permalink
Browse files

Ensure nested preloading works when associations return nil. Closes #…

…11145 [GMFlash]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8894 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent cae1d96 commit 21c75e545a798b75d3ad1eaceea567e725ee655a @NZKoz NZKoz committed Feb 18, 2008
View
@@ -1,5 +1,7 @@
*SVN*
+* Ensure association preloading doesn't break when an association returns nil. ##11145 [GMFlash]
+
* Make dynamic finders respect the :include on HasManyThrough associations. #10998. [cpytel]
* Base#instantiate_time_object only uses Time.zone when Base.time_zone_aware_attributes is true; leverages Time#time_with_datetime_fallback for readability [Geoff Buesing]
@@ -21,7 +21,7 @@ def preload_associations(records, associations, preload_options={})
preload_associations(records, parent, preload_options)
reflection = reflections[parent]
parents = records.map {|record| record.send(reflection.name)}.flatten
- unless parents.empty?
+ unless parents.empty? || parents.first.nil?
parents.first.class.preload_associations(parents, child)
end
end
@@ -76,6 +76,12 @@ def test_loading_with_no_associations
assert_nil Post.find(posts(:authorless).id, :include => :author).author
end
+ def test_nested_loading_with_no_associations
+ assert_nothing_raised do
+ Post.find(posts(:authorless).id, :include => {:author => :author_addresss})
+ end
+ end
+
def test_eager_association_loading_with_belongs_to_and_foreign_keys
pets = Pet.find(:all, :include => :owner)
assert_equal 3, pets.length

0 comments on commit 21c75e5

Please sign in to comment.