Skip to content

Commit

Permalink
Merge [9056] from trunk: Migrations: create_table supports primary_ke…
Browse files Browse the repository at this point in the history
…y_prefix_type. References rails#10314.

git-svn-id: http://svn-commit.rubyonrails.org/rails/branches/2-0-stable@9057 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
jeremy committed Mar 18, 2008
1 parent b96db52 commit 5a5b0b8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 2 additions & 0 deletions activerecord/CHANGELOG
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
11 changes: 8 additions & 3 deletions activerecord/lib/active_record/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 5a5b0b8

Please sign in to comment.