Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Dont try to load the record from the db if preloading didn't find any…

…thing
  • Loading branch information...
commit 0e57c70baf11a7f0211f78a5282f8ba26fbc17b4 1 parent a0454dc
Pratik lifo authored
5 activerecord/lib/active_record/association_preload.rb
View
@@ -157,6 +157,11 @@ def set_association_single_records(id_to_record_map, reflection_name, associated
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
8 activerecord/test/cases/associations/eager_test.rb
View
@@ -830,5 +830,11 @@ def test_include_has_one_using_primary_key
assert_equal expected, firm.account_using_primary_key
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
Please sign in to comment.
Something went wrong with that request. Please try again.