aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2018-06-11 13:06:58 -0400
committerRafael Mendonça França <rafaelmfranca@gmail.com>2018-06-11 13:10:14 -0400
commit4caf1389681a9ab74872b75377ceeb82263fe3b6 (patch)
tree4eda456cc3c0c12298c98e9149ccfefbd766fe17 /activerecord/lib
parentdac0e183025e2f436db9c118abdfb2ee49dada36 (diff)
downloadrails-4caf1389681a9ab74872b75377ceeb82263fe3b6.tar.gz
rails-4caf1389681a9ab74872b75377ceeb82263fe3b6.tar.bz2
rails-4caf1389681a9ab74872b75377ceeb82263fe3b6.zip
Use `-=` to change the update the collection on the association
This also mark the association as loaded given we changed it in memory and avoid the next access to the reader to make a query to the databse.
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/associations/collection_association.rb3
1 files changed, 1 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb
index aa668fa4b4..9a90cd2cc7 100644
--- a/activerecord/lib/active_record/associations/collection_association.rb
+++ b/activerecord/lib/active_record/associations/collection_association.rb
@@ -400,8 +400,7 @@ module ActiveRecord
records.each { |record| callback(:before_remove, record) }
delete_records(existing_records, method) if existing_records.any?
- hashed_records = records.group_by { |record| record }
- target.select! { |record| !hashed_records[record] }
+ self.target -= records
records.each { |record| callback(:after_remove, record) }
end