提交 8dba32f1 编写于 作者: J Jon Leighton

Fix #3987.

上级 d7e714ad
......@@ -102,6 +102,8 @@ def primary_key=(value)
@original_primary_key = @primary_key if defined?(@primary_key)
@primary_key = value && value.to_s
@quoted_primary_key = nil
connection.schema_cache.primary_keys[table_name] = @primary_key if connected?
end
def set_primary_key(value = nil, &block) #:nodoc:
......
......@@ -148,6 +148,16 @@ def test_quoted_primary_key_after_set_primary_key
k.primary_key = "foo"
assert_equal k.connection.quote_column_name("foo"), k.quoted_primary_key
end
def test_set_primary_key_sets_schema_cache
klass = Class.new(ActiveRecord::Base)
klass.table_name = 'fuuuuuu'
klass.connection.create_table(:fuuuuuu, :id => false) { |t| t.integer :omg }
klass.primary_key = 'omg'
assert klass.connection.schema_cache.columns_hash['fuuuuuu']['omg'].primary
ensure
klass.connection.drop_table(:fuuuuuu) if klass.table_exists?
end
end
class PrimaryKeyWithNoConnectionTest < ActiveRecord::TestCase
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册