From 4caf1389681a9ab74872b75377ceeb82263fe3b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Mon, 11 Jun 2018 13:06:58 -0400 Subject: 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. --- activerecord/lib/active_record/associations/collection_association.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'activerecord/lib') 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 -- cgit v1.2.3