mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Fix #3987.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user