Remove unnecessary db call when replacing.

When replacing a has_many association with the same one, there is no
need to do a round-trip to the db to create/and drop a new transaction.

[fixes #14220]
上级 be6f51a4
......@@ -359,7 +359,9 @@ def replace(other_array)
if owner.new_record?
replace_records(other_array, original_target)
else
transaction { replace_records(other_array, original_target) }
if other_array != original_target
transaction { replace_records(other_array, original_target) }
end
end
end
......
......@@ -1242,6 +1242,16 @@ def test_replace_failure
assert_equal orig_accounts, firm.accounts
end
def test_replace_with_same_content
firm = Firm.first
firm.clients = []
firm.save
assert_queries(0, ignore_none: true) do
firm.clients = []
end
end
def test_transactions_when_replacing_on_persisted
good = Client.new(:name => "Good")
bad = Client.new(:name => "Bad", :raise_on_save => true)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册