提交 2202e813 编写于 作者: R Rafael França 提交者: GitHub

Merge pull request #25285 from...

Merge pull request #25285 from kamipo/fix_remove_reference_to_multiple_foreign_keys_in_the_same_table

Fix `remove_reference` to multiple foreign keys in the same table
......@@ -857,6 +857,7 @@ def remove_reference(table_name, ref_name, foreign_key: false, polymorphic: fals
else
foreign_key_options = { to_table: reference_name }
end
foreign_key_options[:column] ||= "#{ref_name}_id"
remove_foreign_key(table_name, **foreign_key_options)
end
......
......@@ -203,6 +203,22 @@ def test_references_foreign_key_with_suffix
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册