aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/has_many_through_association.rb
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2012-05-18 20:48:11 +0100
committerJon Leighton <j@jonathanleighton.com>2012-05-18 20:55:12 +0100
commitb98d1e21635d8776de8893cc09bd86c71f6c78f0 (patch)
treee2b3a7fe3982e4ae4cfaa718a9165d4f3243d9b7 /activerecord/lib/active_record/associations/has_many_through_association.rb
parent2802ad0f72cd030efc3c4ec4f033389564609cec (diff)
downloadrails-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_through_association.rb')
-rw-r--r--activerecord/lib/active_record/associations/has_many_through_association.rb4
1 files changed, 4 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/associations/has_many_through_association.rb b/activerecord/lib/active_record/associations/has_many_through_association.rb
index 53d49fef2e..86c665b5fe 100644
--- a/activerecord/lib/active_record/associations/has_many_through_association.rb
+++ b/activerecord/lib/active_record/associations/has_many_through_association.rb
@@ -126,6 +126,10 @@ module ActiveRecord
def delete_records(records, method)
ensure_not_nested
+ # This is unoptimised; it will load all the target records
+ # even when we just want to delete everything.
+ records = load_target if records == :all
+
scope = through_association.scoped.where(construct_join_attributes(*records))
case method