mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix #3987.
This commit is contained in:
parent
d7e714adac
commit
8dba32f125
2 changed files with 12 additions and 0 deletions
|
@ -102,6 +102,8 @@ module ActiveRecord
|
|||
@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 @@ class PrimaryKeysTest < ActiveRecord::TestCase
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue