diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2016-06-05 16:10:09 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2017-02-11 15:19:53 +0900 |
commit | 6d1440db3eb77170c461d7dab6d43a978a988fae (patch) | |
tree | bce26cd775f93dafe4a5859eea60a4827fa8e9c4 /activerecord/test | |
parent | 6401e03ef6285a93588a162e651e0b15fcb60a19 (diff) | |
download | rails-6d1440db3eb77170c461d7dab6d43a978a988fae.tar.gz rails-6d1440db3eb77170c461d7dab6d43a978a988fae.tar.bz2 rails-6d1440db3eb77170c461d7dab6d43a978a988fae.zip |
Fix `remove_reference` to multiple foreign keys in the same table
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/migration/references_foreign_key_test.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/activerecord/test/cases/migration/references_foreign_key_test.rb b/activerecord/test/cases/migration/references_foreign_key_test.rb index 9418995ea0..f1ddac1ee2 100644 --- a/activerecord/test/cases/migration/references_foreign_key_test.rb +++ b/activerecord/test/cases/migration/references_foreign_key_test.rb @@ -203,6 +203,22 @@ if ActiveRecord::Base.connection.supports_foreign_keys? assert_equal([["testings", "testing_parents", "parent1_id"], ["testings", "testing_parents", "parent2_id"]], fk_definitions) end + + test "multiple foreign keys can be removed to the selected one" do + @connection.create_table :testings do |t| + t.references :parent1, foreign_key: { to_table: :testing_parents } + t.references :parent2, foreign_key: { to_table: :testing_parents } + end + + assert_difference "@connection.foreign_keys('testings').size", -1 do + @connection.remove_reference :testings, :parent1, foreign_key: { to_table: :testing_parents } + end + + fks = @connection.foreign_keys("testings").sort_by(&:column) + + fk_definitions = fks.map { |fk| [fk.from_table, fk.to_table, fk.column] } + assert_equal([["testings", "testing_parents", "parent2_id"]], fk_definitions) + end end end end |