mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Dont try to load the record from the db if preloading didn't find anything
This commit is contained in:
@@ -159,6 +159,11 @@ module ActiveRecord
|
||||
association_proxy.__send__(:set_inverse_instance, associated_record, mapped_record)
|
||||
end
|
||||
end
|
||||
|
||||
id_to_record_map.each do |id, records|
|
||||
next if seen_keys.include?(id.to_s)
|
||||
records.each {|record| record.send("set_#{reflection_name}_target", nil) }
|
||||
end
|
||||
end
|
||||
|
||||
# Given a collection of ActiveRecord objects, constructs a Hash which maps
|
||||
|
||||
@@ -833,4 +833,10 @@ class EagerAssociationTest < ActiveRecord::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
def test_preloading_empty_polymorphic_parent
|
||||
t = Tagging.create!(:taggable_type => 'Post', :taggable_id => Post.maximum(:id) + 1, :tag => tags(:general))
|
||||
|
||||
assert_queries(2) { @tagging = Tagging.preload(:taggable).find(t.id) }
|
||||
assert_no_queries { assert ! @tagging.taggable }
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user