aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2008-03-18 18:23:14 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2008-03-18 18:23:14 +0000
commitdfa68883113045aad4bfab87c82b54d0c98d0a89 (patch)
treebab2f4c23af96f1bb8b8a9850f9d503249df46af /activerecord/lib
parent856a4dcf1207e888b23016cac6a64582051aa0ff (diff)
downloadrails-dfa68883113045aad4bfab87c82b54d0c98d0a89.tar.gz
rails-dfa68883113045aad4bfab87c82b54d0c98d0a89.tar.bz2
rails-dfa68883113045aad4bfab87c82b54d0c98d0a89.zip
Migrations: create_table supports primary_key_prefix_type. Closes #10314.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9056 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib')
-rwxr-xr-xactiverecord/lib/active_record/base.rb11
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb2
2 files changed, 9 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 4bd06d54e9..4531c12110 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -974,14 +974,19 @@ module ActiveRecord #:nodoc:
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
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
index b471b153de..b1f1fd4d73 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
@@ -89,7 +89,7 @@ module ActiveRecord
# 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