diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2018-06-11 11:27:55 -0400 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2018-06-11 11:27:55 -0400 |
commit | dac0e183025e2f436db9c118abdfb2ee49dada36 (patch) | |
tree | f576584cedd50cd709c060da6d8b559e23fdd57e /activerecord/lib | |
parent | d3f659e5266a0154e252a05e63e806d4fac4c8e6 (diff) | |
parent | 34667957f40e3b2f29cacbb3b699c933b9e5ed67 (diff) | |
download | rails-dac0e183025e2f436db9c118abdfb2ee49dada36.tar.gz rails-dac0e183025e2f436db9c118abdfb2ee49dada36.tar.bz2 rails-dac0e183025e2f436db9c118abdfb2ee49dada36.zip |
Merge pull request #29939 from arthurchui/activerecord-delete-associations-loop
Use hash lookup for deleting existing associations from `target`
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/collection_association.rb | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb index 48cb819484..aa668fa4b4 100644 --- a/activerecord/lib/active_record/associations/collection_association.rb +++ b/activerecord/lib/active_record/associations/collection_association.rb @@ -400,7 +400,8 @@ module ActiveRecord records.each { |record| callback(:before_remove, record) } delete_records(existing_records, method) if existing_records.any? - records.each { |record| target.delete(record) } + hashed_records = records.group_by { |record| record } + target.select! { |record| !hashed_records[record] } records.each { |record| callback(:after_remove, record) } end |