aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activerecord/lib/active_record/associations/collection_association.rb6
1 files changed, 5 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb
index 8a028c8996..17795f1b7d 100644
--- a/activerecord/lib/active_record/associations/collection_association.rb
+++ b/activerecord/lib/active_record/associations/collection_association.rb
@@ -402,7 +402,11 @@ module ActiveRecord
return memory if persisted.empty?
persisted.map! do |record|
- mem_record = memory.delete(record)
+ mem_record_index = memory.index(record)
+ if mem_record_index
+ mem_record = memory.at(mem_record_index)
+ memory.delete_at(mem_record_index)
+ end
if mem_record
(record.attribute_names - mem_record.changes.keys).each do |name|