提交 4e380828 编写于 作者: J Julius de Bruijn 提交者: Jon Leighton

If the table behind has no primary key, do not ask again and just return nil.

上级 7a4949e7
...@@ -33,7 +33,8 @@ def dangerous_attribute_method?(method_name) ...@@ -33,7 +33,8 @@ def dangerous_attribute_method?(method_name)
# Defines the primary key field -- can be overridden in subclasses. Overwriting will negate any effect of the # Defines the primary key field -- can be overridden in subclasses. Overwriting will negate any effect of the
# primary_key_prefix_type setting, though. # primary_key_prefix_type setting, though.
def primary_key def primary_key
@primary_key ||= reset_primary_key @primary_key = reset_primary_key unless defined? @primary_key
@primary_key
end end
# Returns a quoted version of the primary key name, used to construct SQL statements. # Returns a quoted version of the primary key name, used to construct SQL statements.
......
...@@ -53,6 +53,11 @@ def test_attribute_present_with_booleans ...@@ -53,6 +53,11 @@ def test_attribute_present_with_booleans
assert Boolean.find(b4.id).attribute_present?(:value) assert Boolean.find(b4.id).attribute_present?(:value)
end end
def test_caching_nil_primary_key
Minimalistic.expects(:reset_primary_key).returns(nil).once
Minimalistic.create!
end
def test_attribute_keys_on_new_instance def test_attribute_keys_on_new_instance
t = Topic.new t = Topic.new
assert_equal nil, t.title, "The topics table has a title column, so it should be nil" assert_equal nil, t.title, "The topics table has a title column, so it should be nil"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册