aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-11-19 13:53:06 -0200
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-11-19 13:53:06 -0200
commite4300196721417237c3bfca0fc36313ea5ed7096 (patch)
treed8ff8cb7851fe38c58dd557fc6b2c51c7ec32688 /activerecord
parent75cfca0521f4e7ba983b5d2f2f23b95870880ea4 (diff)
parent995c697511a4e77fbe1e00793486ae07b18c5017 (diff)
downloadrails-e4300196721417237c3bfca0fc36313ea5ed7096.tar.gz
rails-e4300196721417237c3bfca0fc36313ea5ed7096.tar.bz2
rails-e4300196721417237c3bfca0fc36313ea5ed7096.zip
Merge pull request #17662 from dtaniwaki/support-symbol-foreign-key-column-to-delete
Support symbol foreign key to delete
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb2
-rw-r--r--activerecord/test/cases/migration/foreign_key_test.rb8
2 files changed, 9 insertions, 1 deletions
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 cbf87df356..cc86c3776e 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
@@ -740,7 +740,7 @@ module ActiveRecord
end
fk_name_to_delete = options.fetch(:name) do
- fk_to_delete = foreign_keys(from_table).detect {|fk| fk.column == options[:column] }
+ fk_to_delete = foreign_keys(from_table).detect {|fk| fk.column == options[:column].to_s }
if fk_to_delete
fk_to_delete.name
diff --git a/activerecord/test/cases/migration/foreign_key_test.rb b/activerecord/test/cases/migration/foreign_key_test.rb
index 52e963a14f..51e21528c2 100644
--- a/activerecord/test/cases/migration/foreign_key_test.rb
+++ b/activerecord/test/cases/migration/foreign_key_test.rb
@@ -162,6 +162,14 @@ module ActiveRecord
assert_equal [], @connection.foreign_keys("astronauts")
end
+ def test_remove_foreign_key_by_symbol_column
+ @connection.add_foreign_key :astronauts, :rockets, column: :rocket_id
+
+ assert_equal 1, @connection.foreign_keys("astronauts").size
+ @connection.remove_foreign_key :astronauts, column: :rocket_id
+ assert_equal [], @connection.foreign_keys("astronauts")
+ end
+
def test_remove_foreign_key_by_name
@connection.add_foreign_key :astronauts, :rockets, column: "rocket_id", name: "fancy_named_fk"