Skip to content
Browse files

Don't store defaults in the schema cache

  • Loading branch information...
1 parent dee94d8 commit 7f20bb995aa34c6c6869543209595ff811e9dbc3 @jonleighton jonleighton committed Dec 16, 2011
View
4 activerecord/lib/active_record/attribute_methods/primary_key.rb
@@ -72,8 +72,8 @@ def get_primary_key(base_name) #:nodoc:
when :table_name_with_underscore
base_name.foreign_key
else
- if ActiveRecord::Base != self && connection.schema_cache.table_exists?(table_name)
- connection.primary_key(table_name)
+ if ActiveRecord::Base != self && table_name
+ connection.schema_cache.primary_keys[table_name]
else
'id'
end
View
5 activerecord/lib/active_record/connection_adapters/schema_cache.rb
@@ -8,7 +8,7 @@ def initialize(conn)
@connection = conn
@tables = {}
- @columns = Hash.new do |h, table_name|
+ @columns = Hash.new do |h, table_name|
h[table_name] = conn.columns(table_name, "#{table_name} Columns")
end
@@ -19,8 +19,7 @@ def initialize(conn)
end
@primary_keys = Hash.new do |h, table_name|
- h[table_name] = table_exists?(table_name) ?
- conn.primary_key(table_name) : 'id'
+ h[table_name] = table_exists?(table_name) ? conn.primary_key(table_name) : nil
end
end
View
1 activerecord/test/cases/base_test.rb
@@ -1494,6 +1494,7 @@ def test_set_primary_key_with_block
def test_original_primary_key
k = Class.new(ActiveRecord::Base)
def k.name; "Foo"; end
+ k.table_name = "posts"
k.primary_key = "bar"
assert_deprecated do
View
2 activerecord/test/cases/connection_adapters/schema_cache_test.rb
@@ -13,7 +13,7 @@ def test_primary_key
end
def test_primary_key_for_non_existent_table
- assert_equal 'id', @cache.primary_keys['omgponies']
+ assert_nil @cache.primary_keys['omgponies']
end
def test_caches_columns

0 comments on commit 7f20bb9

Please sign in to comment.
Something went wrong with that request. Please try again.