mirror of
https://github.com/github/rails.git
synced 2026-01-29 00:08:15 -05:00
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
This commit is contained in:
@@ -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 @@ module ActiveRecord
|
||||
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 @@ class EagerAssociationTest < ActiveRecord::TestCase
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user