aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordtaniwaki <daisuketaniwaki@gmail.com>2014-11-19 10:17:44 +0900
committerdtaniwaki <daisuketaniwaki@gmail.com>2014-11-19 10:17:44 +0900
commit995c697511a4e77fbe1e00793486ae07b18c5017 (patch)
tree962091a516c8631355df4030d69eaa6c8863ea51
parent3098579f276d5cecbca0b57e35526b99fadfbe5f (diff)
downloadrails-995c697511a4e77fbe1e00793486ae07b18c5017.tar.gz
rails-995c697511a4e77fbe1e00793486ae07b18c5017.tar.bz2
rails-995c697511a4e77fbe1e00793486ae07b18c5017.zip
Support symbol foreign key to delete
-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"