未验证 提交 e715a647 编写于 作者: G George Claghorn 提交者: GitHub

Merge pull request #33617 from bogdanvlviv/follow-up-33530

Follow up #33530
* Allow `:to_table` option to `invert_remove_foreign_key`.
Example:
remove_foreign_key :accounts, to_table: :owners
*Nikolay Epifanov*, *Rich Chen*
* Add environment & load_config dependency to `bin/rake db:seed` to enable
seed load in environments without Rails and custom DB configuration
......@@ -73,9 +81,5 @@
*DHH*
* Allow `to_table` in `invert_remove_foreign_key`.
*Nikolay Epifanov*, *Rich Chen*
Please check [5-2-stable](https://github.com/rails/rails/blob/5-2-stable/activerecord/CHANGELOG.md) for previous changes.
......@@ -980,9 +980,9 @@ def add_foreign_key(from_table, to_table, options = {})
#
# remove_foreign_key :accounts, column: :owner_id
#
# Removes the foreign key on +accounts.owner_id+. in a reversible manner
# Removes the foreign key on +accounts.owner_id+.
#
# remove_foreign_key :accounts, column: :owner_id, to_table: :owners
# remove_foreign_key :accounts, to_table: :owners
#
# Removes the foreign key named +special_fk_name+ on the +accounts+ table.
#
......@@ -991,7 +991,7 @@ def add_foreign_key(from_table, to_table, options = {})
# The +options+ hash accepts the same keys as SchemaStatements#add_foreign_key
# with an addition of
# [<tt>:to_table</tt>]
# The table contains the referenced primary key.
# The name of the table that contains the referenced primary key.
def remove_foreign_key(from_table, options_or_to_table = {})
return unless supports_foreign_keys?
......
......@@ -329,6 +329,11 @@ def test_invert_remove_foreign_key_with_primary_key
assert_equal [:add_foreign_key, [:dogs, :people, primary_key: "person_id"]], enable
end
def test_invert_remove_foreign_key_with_primary_key_and_to_table_in_options
enable = @recorder.inverse_of :remove_foreign_key, [:dogs, to_table: :people, primary_key: "uuid"]
assert_equal [:add_foreign_key, [:dogs, :people, primary_key: "uuid"]], enable
end
def test_invert_remove_foreign_key_with_on_delete_on_update
enable = @recorder.inverse_of :remove_foreign_key, [:dogs, :people, on_delete: :nullify, on_update: :cascade]
assert_equal [:add_foreign_key, [:dogs, :people, on_delete: :nullify, on_update: :cascade]], enable
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册