mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
If the table behind has no primary key, do not ask again and just return nil.
This commit is contained in:
committed by
Jon Leighton
parent
7a4949e7d5
commit
4e380828ff
@@ -33,7 +33,8 @@ module ActiveRecord
|
||||
# Defines the primary key field -- can be overridden in subclasses. Overwriting will negate any effect of the
|
||||
# primary_key_prefix_type setting, though.
|
||||
def primary_key
|
||||
@primary_key ||= reset_primary_key
|
||||
@primary_key = reset_primary_key unless defined? @primary_key
|
||||
@primary_key
|
||||
end
|
||||
|
||||
# Returns a quoted version of the primary key name, used to construct SQL statements.
|
||||
|
||||
@@ -53,6 +53,11 @@ class AttributeMethodsTest < ActiveRecord::TestCase
|
||||
assert Boolean.find(b4.id).attribute_present?(:value)
|
||||
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
|
||||
t = Topic.new
|
||||
assert_equal nil, t.title, "The topics table has a title column, so it should be nil"
|
||||
|
||||
Reference in New Issue
Block a user