mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #14234 from arthurnn/fix_trans_on_replace
Remove unnecessary db call when replacing.
This commit is contained in:
commit
f60b524919
2 changed files with 13 additions and 1 deletions
|
@ -359,7 +359,9 @@ module ActiveRecord
|
|||
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 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
|
|||
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)
|
||||
|
|
Loading…
Reference in a new issue