Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Perf fix

If we're deleting all records in an association, don't add a IN(..)
clause to the query.

Fixes #3672.
  • Loading branch information...
commit fec85cf10d831ab90386a549ea558b0dd58a813f 1 parent 2ef4947
Jon Leighton jonleighton authored
5 activerecord/CHANGELOG.md
View
@@ -67,6 +67,11 @@
## Rails 3.1.3 (unreleased) ##
+* Perf fix: If we're deleting all records in an association, don't add a IN(..) clause
+ to the query. *GH 3672*
+
+ *Jon Leighton*
+
* Fix bug with referencing other mysql databases in set_table_name. *GH 3690*
* Fix performance bug with mysql databases on a server with lots of other databses. *GH 3678*
8 activerecord/lib/active_record/associations/has_many_association.rb
View
@@ -89,8 +89,12 @@ def delete_records(records, method)
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)
+ scope = scoped
+
+ unless records == load_target
+ 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)
Please sign in to comment.
Something went wrong with that request. Please try again.