Skip to content

Commit 5a5b0b8

Browse files
committed
Merge [9056] from trunk: Migrations: create_table supports primary_key_prefix_type. References rails#10314.
git-svn-id: http://svn-commit.rubyonrails.org/rails/branches/2-0-stable@9057 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
1 parent b96db52 commit 5a5b0b8

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

activerecord/CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
*SVN*
22

3+
* Migrations: create_table supports primary_key_prefix_type. #10314 [student, thechrisoshow]
4+
35
* Ensure that ActiveRecord::Calculations disambiguates field names with the table name. #11027 [cavalle]
46

57
* Ensure that modifying has_and_belongs_to_many actions clear the query cache. Closes #10840 [john.andrews]

activerecord/lib/active_record/base.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -966,14 +966,19 @@ def primary_key
966966
end
967967

968968
def reset_primary_key #:nodoc:
969+
key = get_primary_key(base_class.name)
970+
set_primary_key(key)
971+
key
972+
end
973+
974+
def get_primary_key(base_name) #:nodoc:
969975
key = 'id'
970976
case primary_key_prefix_type
971977
when :table_name
972-
key = Inflector.foreign_key(base_class.name, false)
978+
key = Inflector.foreign_key(base_name, false)
973979
when :table_name_with_underscore
974-
key = Inflector.foreign_key(base_class.name)
980+
key = Inflector.foreign_key(base_name)
975981
end
976-
set_primary_key(key)
977982
key
978983
end
979984

activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def columns(table_name, name = nil) end
8989
# See also TableDefinition#column for details on how to create columns.
9090
def create_table(table_name, options = {})
9191
table_definition = TableDefinition.new(self)
92-
table_definition.primary_key(options[:primary_key] || "id") unless options[:id] == false
92+
table_definition.primary_key(options[:primary_key] || Base.get_primary_key(table_name)) unless options[:id] == false
9393

9494
yield table_definition
9595

0 commit comments

Comments
 (0)