class method
self.destroy_all
Ruby on Rails 2.2.3
Since v2.2.3 Last seen in v2.3.18Available in: v2.2.3 v2.3.18
Signature
self.destroy_all(conditions = nil)
Destroys the records matching conditions by instantiating each record and calling their destroy method. This means at least 2*N database queries to destroy N records, so avoid destroy_all if you are deleting many records. If you want to simply delete records without worrying about dependent associations or callbacks, use the much faster delete_all method instead.
Parameters
-
conditions- Conditions are specified the same way as withfindmethod.
Example
Person.destroy_all("last_login < '2004-04-04'")
This loads and destroys each person one by one, including its dependent associations and before_ and after_destroy callbacks.
conditions can be anything that find also accepts:
Person.destroy_all(:last_login => 6.hours.ago)
Parameters
-
conditionsopt = nil
Source
# File activerecord/lib/active_record/base.rb, line 839
def destroy_all(conditions = nil)
find(:all, :conditions => conditions).each { |object| object.destroy }
end
Defined in activerecord/lib/active_record/base.rb line 839
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::Base