diff options
author | Jon Leighton <j@jonathanleighton.com> | 2012-05-18 20:48:11 +0100 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2012-05-18 20:55:12 +0100 |
commit | b98d1e21635d8776de8893cc09bd86c71f6c78f0 (patch) | |
tree | e2b3a7fe3982e4ae4cfaa718a9165d4f3243d9b7 /activerecord/lib/active_record/associations/has_many_association.rb | |
parent | 2802ad0f72cd030efc3c4ec4f033389564609cec (diff) | |
download | rails-b98d1e21635d8776de8893cc09bd86c71f6c78f0.tar.gz rails-b98d1e21635d8776de8893cc09bd86c71f6c78f0.tar.bz2 rails-b98d1e21635d8776de8893cc09bd86c71f6c78f0.zip |
Perf: Don't load the association for #delete_all.
Bug #6289
Conflicts:
activerecord/test/cases/associations/has_many_associations_test.rb
Diffstat (limited to 'activerecord/lib/active_record/associations/has_many_association.rb')
-rw-r--r-- | activerecord/lib/active_record/associations/has_many_association.rb | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/associations/has_many_association.rb b/activerecord/lib/active_record/associations/has_many_association.rb index 059e6c77bc..e631579087 100644 --- a/activerecord/lib/active_record/associations/has_many_association.rb +++ b/activerecord/lib/active_record/associations/has_many_association.rb @@ -89,8 +89,12 @@ module ActiveRecord records.each { |r| r.destroy } update_counter(-records.length) unless inverse_updates_counter_cache? else - keys = records.map { |r| r[reflection.association_primary_key] } - scope = scoped.where(reflection.association_primary_key => keys) + if records == :all + scope = scoped + else + keys = records.map { |r| r[reflection.association_primary_key] } + scope = scoped.where(reflection.association_primary_key => keys) + end if method == :delete_all update_counter(-scope.delete_all) |