method
delete_by
v8.0.0 -
Show latest stable
- Class:
ActiveRecord::Relation
delete_by(*args)public
Finds and deletes all records matching the specified conditions. This is short-hand for relation.where(condition).delete_all. Returns the number of rows affected.
If no record is found, returns 0 as zero rows were affected.
Person.delete_by(id: 13) Person.delete_by(name: 'Spartacus', rating: 4) Person.delete_by("published_at < ?", 2.weeks.ago)