未验证 提交 9ae3ddbb 编写于 作者: R Ryuta Kamizono 提交者: GitHub

Merge pull request #19388 from yakara-ltd/fix-habtm-fixture-order

Avoid violating key constraints in fixture HABTM associations
...@@ -45,6 +45,9 @@ def initialize(table_name, model_class:, fixtures:, config:) ...@@ -45,6 +45,9 @@ def initialize(table_name, model_class:, fixtures:, config:)
# track any join tables we need to insert later # track any join tables we need to insert later
@tables = Hash.new { |h, table| h[table] = [] } @tables = Hash.new { |h, table| h[table] = [] }
# ensure this table is loaded before any HABTM associations
@tables[table_name] = nil
build_table_rows_from(fixtures, config) build_table_rows_from(fixtures, config)
end end
......
...@@ -619,6 +619,10 @@ def test_has_many_through_with_renamed_table ...@@ -619,6 +619,10 @@ def test_has_many_through_with_renamed_table
assert_equal load_has_and_belongs_to_many["parrots_treasures"], rows["parrot_treasures"] assert_equal load_has_and_belongs_to_many["parrots_treasures"], rows["parrot_treasures"]
end end
def test_has_and_belongs_to_many_order
assert_equal ["parrots", "parrots_treasures"], load_has_and_belongs_to_many.keys
end
def load_has_and_belongs_to_many def load_has_and_belongs_to_many
parrot = make_model "Parrot" parrot = make_model "Parrot"
parrot.has_and_belongs_to_many :treasures parrot.has_and_belongs_to_many :treasures
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册