Permalink
Browse files

Don't find belongs_to target when the foreign_key is NULL. Fixes #2828

  • Loading branch information...
1 parent a7f5532 commit 78c896ce83f96df2a133ac314b317c1628101f31 Georg Friedrich committed with tenderlove Sep 5, 2011
@@ -20,6 +20,10 @@ def updated?
private
+ def find_target?
+ !loaded? && foreign_key_present? && klass
+ end
+
def update_counters(record)
counter_cache_name = reflection.counter_cache_column
@@ -343,6 +343,12 @@ def test_polymorphic_setting_foreign_key_after_nil_target_loaded
assert_equal members(:groucho), sponsor.sponsorable
end
+ def test_dont_find_target_when_foreign_key_is_null
+ tagging = taggings(:thinking_general)
+ queries = assert_sql { tagging.super_tag }
+ assert_equal 0, queries.length
+ end
+
def test_field_name_same_as_foreign_key
computer = Computer.find(1)
assert_not_nil computer.developer, ":foreign key == attribute didn't lock up" # '

1 comment on commit 78c896c

@jonleighton
Member

common, CHANGELOG :) 431d766

Please sign in to comment.