1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
This commit is contained in:
Jon Leighton 2011-12-15 13:23:18 +00:00
parent d7e714adac
commit 8dba32f125
2 changed files with 12 additions and 0 deletions

View file

@ -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:

View file

@ -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