method
destroy_all
v2.2.1 -
Show latest stable
-
0 notes -
Class: ActiveRecord::Base
- 1.0.0 (0)
- 1.1.6 (0)
- 1.2.6 (0)
- 2.0.3 (16)
- 2.1.0 (0)
- 2.2.1 (4)
- 2.3.8 (12)
- 3.0.0
- 3.0.9
- 3.1.0
- 3.2.1
- 3.2.8
- 3.2.13
- 4.0.2
- 4.1.8
- 4.2.1
- 4.2.7
- 4.2.9
- 5.0.0.1
- 5.1.7
- 5.2.3
- 6.0.0
- 6.1.3.1
- 6.1.7.7
- 7.0.0
- 7.1.3.2
- 7.1.3.4
- What's this?
destroy_all(conditions = nil)
public
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 with find method.
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)