aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/migration
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2019-03-06 23:30:11 +0900
committerRyuta Kamizono <kamipo@gmail.com>2019-03-06 23:45:08 +0900
commitfd18b98dd90d738af265cf5b8f0d66ca11010132 (patch)
treeadaa5ffd1a5d3ef8fda9ec2945db1888ff7cfba5 /activerecord/lib/active_record/migration
parentb366be3b5b28f01c8a55d67a5161ec36f53d555c (diff)
downloadrails-fd18b98dd90d738af265cf5b8f0d66ca11010132.tar.gz
rails-fd18b98dd90d738af265cf5b8f0d66ca11010132.tar.bz2
rails-fd18b98dd90d738af265cf5b8f0d66ca11010132.zip
Allow `remove_foreign_key` with both `to_table` and `options`
Foreign keys could be created to the same table. So `remove_foreign_key :from_table, :to_table` is sometimes ambiguous. This allows `remove_foreign_key` to remove the select one on the same table with giving both `to_table` and `options`.
Diffstat (limited to 'activerecord/lib/active_record/migration')
-rw-r--r--activerecord/lib/active_record/migration/command_recorder.rb17
1 files changed, 4 insertions, 13 deletions
diff --git a/activerecord/lib/active_record/migration/command_recorder.rb b/activerecord/lib/active_record/migration/command_recorder.rb
index 82f5121d94..8e7f596076 100644
--- a/activerecord/lib/active_record/migration/command_recorder.rb
+++ b/activerecord/lib/active_record/migration/command_recorder.rb
@@ -231,24 +231,15 @@ module ActiveRecord
end
def invert_remove_foreign_key(args)
- from_table, options_or_to_table, options_or_nil = args
+ options = args.extract_options!
+ from_table, to_table = args
- to_table = if options_or_to_table.is_a?(Hash)
- options_or_to_table[:to_table]
- else
- options_or_to_table
- end
-
- remove_options = if options_or_to_table.is_a?(Hash)
- options_or_to_table.except(:to_table)
- else
- options_or_nil
- end
+ to_table ||= options.delete(:to_table)
raise ActiveRecord::IrreversibleMigration, "remove_foreign_key is only reversible if given a second table" if to_table.nil?
reversed_args = [from_table, to_table]
- reversed_args << remove_options if remove_options.present?
+ reversed_args << options unless options.empty?
[:add_foreign_key, reversed_args]
end