Permalink
Browse files

Merge [9056] from trunk: Migrations: create_table supports primary_ke…

…y_prefix_type. References #10314.

git-svn-id: http://svn-commit.rubyonrails.org/rails/branches/2-0-stable@9057 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent b96db52 commit 5a5b0b8b3be2e724520e0d1c6dea00c98d599165 @jeremy jeremy committed Mar 18, 2008
View
2 activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Migrations: create_table supports primary_key_prefix_type. #10314 [student, thechrisoshow]
+
* Ensure that ActiveRecord::Calculations disambiguates field names with the table name. #11027 [cavalle]
* Ensure that modifying has_and_belongs_to_many actions clear the query cache. Closes #10840 [john.andrews]
View
11 activerecord/lib/active_record/base.rb
@@ -966,14 +966,19 @@ def primary_key
end
def reset_primary_key #:nodoc:
+ key = get_primary_key(base_class.name)
+ set_primary_key(key)
+ key
+ end
+
+ def get_primary_key(base_name) #:nodoc:
key = 'id'
case primary_key_prefix_type
when :table_name
- key = Inflector.foreign_key(base_class.name, false)
+ key = Inflector.foreign_key(base_name, false)
when :table_name_with_underscore
- key = Inflector.foreign_key(base_class.name)
+ key = Inflector.foreign_key(base_name)
end
- set_primary_key(key)
key
end
View
2 activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
@@ -89,7 +89,7 @@ def columns(table_name, name = nil) end
# See also TableDefinition#column for details on how to create columns.
def create_table(table_name, options = {})
table_definition = TableDefinition.new(self)
- table_definition.primary_key(options[:primary_key] || "id") unless options[:id] == false
+ table_definition.primary_key(options[:primary_key] || Base.get_primary_key(table_name)) unless options[:id] == false
yield table_definition

0 comments on commit 5a5b0b8

Please sign in to comment.