aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2010-01-20 18:33:14 +0530
committerPratik Naik <pratiknaik@gmail.com>2010-01-20 18:33:14 +0530
commitf216fadc0e4a54d1807fe5a9462f7bd34e9024b0 (patch)
tree8c47b27d0f1b0981b37b836103fcc3dc8ac48d1f /activerecord
parent97568056763dc3bca7804a1426fae32a2031cfec (diff)
downloadrails-f216fadc0e4a54d1807fe5a9462f7bd34e9024b0.tar.gz
rails-f216fadc0e4a54d1807fe5a9462f7bd34e9024b0.tar.bz2
rails-f216fadc0e4a54d1807fe5a9462f7bd34e9024b0.zip
Delegate delete_all to Relation
Diffstat (limited to 'activerecord')
-rwxr-xr-xactiverecord/lib/active_record/base.rb23
-rw-r--r--activerecord/lib/active_record/relation.rb21
2 files changed, 20 insertions, 24 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 6b7faa763b..1896b49977 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -556,7 +556,7 @@ module ActiveRecord #:nodoc:
end
alias :colorize_logging= :colorize_logging
- delegate :find, :first, :last, :all, :destroy, :destroy_all, :exists?, :delete, :to => :scoped
+ delegate :find, :first, :last, :all, :destroy, :destroy_all, :exists?, :delete, :delete_all, :to => :scoped
delegate :select, :group, :order, :limit, :joins, :where, :preload, :eager_load, :includes, :from, :lock, :readonly, :having, :to => :scoped
delegate :count, :average, :minimum, :maximum, :sum, :calculate, :to => :scoped
@@ -688,27 +688,6 @@ module ActiveRecord #:nodoc:
relation.update(sanitize_sql_for_assignment(updates))
end
- # Deletes the records matching +conditions+ without instantiating the records first, and hence not
- # calling the +destroy+ method nor invoking callbacks. This is a single SQL DELETE statement that
- # goes straight to the database, much more efficient than +destroy_all+. Be careful with relations
- # though, in particular <tt>:dependent</tt> rules defined on associations are not honored. Returns
- # the number of rows affected.
- #
- # ==== Parameters
- #
- # * +conditions+ - Conditions are specified the same way as with +find+ method.
- #
- # ==== Example
- #
- # Post.delete_all("person_id = 5 AND (category = 'Something' OR category = 'Else')")
- # Post.delete_all(["person_id = ? AND (category = ? OR category = ?)", 5, 'Something', 'Else'])
- #
- # Both calls delete the affected posts all at once with a single DELETE statement. If you need to destroy dependent
- # associations or call your <tt>before_*</tt> or +after_destroy+ callbacks, use the +destroy_all+ method instead.
- def delete_all(conditions = nil)
- where(conditions).delete_all
- end
-
# Returns the result of an SQL statement that should only include a COUNT(*) in the SELECT part.
# The use of this method should be restricted to complicated SQL queries that can't be executed
# using the ActiveRecord::Calculations class methods. Look into those before using this.
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb
index a253dbd19d..a6c283e03c 100644
--- a/activerecord/lib/active_record/relation.rb
+++ b/activerecord/lib/active_record/relation.rb
@@ -146,8 +146,25 @@ module ActiveRecord
end
end
- def delete_all
- arel.delete.tap { reset }
+ # Deletes the records matching +conditions+ without instantiating the records first, and hence not
+ # calling the +destroy+ method nor invoking callbacks. This is a single SQL DELETE statement that
+ # goes straight to the database, much more efficient than +destroy_all+. Be careful with relations
+ # though, in particular <tt>:dependent</tt> rules defined on associations are not honored. Returns
+ # the number of rows affected.
+ #
+ # ==== Parameters
+ #
+ # * +conditions+ - Conditions are specified the same way as with +find+ method.
+ #
+ # ==== Example
+ #
+ # Post.delete_all("person_id = 5 AND (category = 'Something' OR category = 'Else')")
+ # Post.delete_all(["person_id = ? AND (category = ? OR category = ?)", 5, 'Something', 'Else'])
+ #
+ # Both calls delete the affected posts all at once with a single DELETE statement. If you need to destroy dependent
+ # associations or call your <tt>before_*</tt> or +after_destroy+ callbacks, use the +destroy_all+ method instead.
+ def delete_all(conditions = nil)
+ conditions ? where(conditions).delete_all : arel.delete.tap { reset }
end
# Deletes the row with a primary key matching the +id+ argument, using a