Permalink
Browse files

add support of primary_key option

  • Loading branch information...
1 parent d53bacb commit 29592a2a17d3195308e66bd339fc35b850511fe4 Zhang Yuanyi committed with Oct 9, 2009
Showing with 3 additions and 2 deletions.
  1. +3 −2 lib/auto_migrations.rb
@@ -79,7 +79,8 @@ def auto_create_table(method, *args, &block)
# Grab schema columns (lifted from active_record/connection_adapters/abstract/schema_statements.rb)
table_definition = ActiveRecord::ConnectionAdapters::TableDefinition.new(ActiveRecord::Base.connection)
- table_definition.primary_key(options[:primary_key] || "id") unless options[:id] == false
+ primary_key = options[:primary_key] || "id"
+ table_definition.primary_key(primary_key) unless options[:id] == false
yield table_definition
fields_in_schema = table_definition.columns.inject({}) do |hash, column|
hash[column.name.to_s] = column
@@ -102,7 +103,7 @@ def auto_create_table(method, *args, &block)
end
(fields_in_schema.keys & fields_in_db.keys).each do |field|
- if field != 'id' #ActiveRecord::Base.get_primary_key(table_name)
+ if field != primary_key #ActiveRecord::Base.get_primary_key(table_name)
changed = false # flag
new_type = fields_in_schema[field].type.to_sym
new_attr = {}

0 comments on commit 29592a2

Please sign in to comment.