提交 21750122 编写于 作者: G Georg Friedrich 提交者: Aaron Patterson

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

上级 7f7e362c
......@@ -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
......
......@@ -352,6 +352,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" # '
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册