aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/collection_association.rb
diff options
context:
space:
mode:
authorArthur Neves <arthurnn@gmail.com>2014-02-28 17:00:38 -0500
committerArthur Neves <arthurnn@gmail.com>2014-02-28 17:00:38 -0500
commit774160b9ad6908435bf3485e7ac98633deff76c6 (patch)
tree37c2e322ff4eae74c8d314912293b07efb46218b /activerecord/lib/active_record/associations/collection_association.rb
parentbe6f51a487eb412ca29765aa7e84d2f13a688891 (diff)
downloadrails-774160b9ad6908435bf3485e7ac98633deff76c6.tar.gz
rails-774160b9ad6908435bf3485e7ac98633deff76c6.tar.bz2
rails-774160b9ad6908435bf3485e7ac98633deff76c6.zip
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]
Diffstat (limited to 'activerecord/lib/active_record/associations/collection_association.rb')
-rw-r--r--activerecord/lib/active_record/associations/collection_association.rb4
1 files changed, 3 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb
index 270871c866..9a2900843e 100644
--- a/activerecord/lib/active_record/associations/collection_association.rb
+++ b/activerecord/lib/active_record/associations/collection_association.rb
@@ -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