Skip to content
Browse files

alte optionen noch weiter unterstützen

  • Loading branch information...
1 parent 5c7609d commit d5f775a4a7bb9330406ae626eabfbd7e96a3d260 @TeaMoe committed Mar 13, 2012
View
20 lib/foreign_key_migrations.rb
@@ -20,6 +20,26 @@ def references(table_name, column_name, options = {})
[$1.pluralize, :id]
end
end
+
+ def add_foreign_key adapter, table_name, column_name, column_options
+ references = ForeignKeyMigrations.references(table_name, column_name, column_options)
+ convert_legacy_options!(column_options)
+ adapter.add_foreign_key table_name, references.first, column_options.merge(:column => column_name) if references
+ end
+
+ def convert_legacy_options! options
+ on_delete = options.delete :on_delete
+ if on_delete
+ options[:dependent] = case on_delete
+ when :set_null
+ :nullify
+ when :cascade
+ :delete
+ else
+ on_delete
+ end
+ end
+ end
end
require 'foreign_key_migrations/railtie' if defined?(Rails)
View
3 lib/foreign_key_migrations/connection_adapters/schema_statements.rb
@@ -13,8 +13,7 @@ def create_table_with_foreign_key_migrations(table_name, options = {}, &block)
@table_definition.column_definitions.each do |column_params|
column_name = column_params.first
column_options = column_params.last
- references = ForeignKeyMigrations.references(table_name, column_name, column_options)
- add_foreign_key table_name, references.first, column_options.merge(:column => column_name) if references
+ ForeignKeyMigrations.add_foreign_key self, table_name, column_name, column_options
end
end

0 comments on commit d5f775a

Please sign in to comment.
Something went wrong with that request. Please try again.