Permalink
Browse files

Fix #3987.

  • Loading branch information...
1 parent d7e714a commit 8dba32f125cc0b79fe453f38b1044c7bf9fb52ce @jonleighton jonleighton committed Dec 15, 2011
View
2 activerecord/lib/active_record/attribute_methods/primary_key.rb
@@ -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:
View
10 activerecord/test/cases/primary_keys_test.rb
@@ -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

0 comments on commit 8dba32f

Please sign in to comment.