aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
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
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')
-rw-r--r--activerecord/lib/active_record/associations/collection_association.rb3
-rw-r--r--activerecord/test/cases/associations/has_many_through_associations_test.rb2
2 files changed, 2 insertions, 3 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
diff --git a/activerecord/test/cases/associations/has_many_through_associations_test.rb b/activerecord/test/cases/associations/has_many_through_associations_test.rb
index d5573b6d02..259e4eb4b7 100644
--- a/activerecord/test/cases/associations/has_many_through_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb
@@ -357,7 +357,7 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
posts(:welcome).people.delete(people(:michael))
end
- assert_queries(1) do
+ assert_queries(0) do
assert_empty posts(:welcome).people
end