v6.1.7.7 - Show latest stable - 0 notes - 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)
Show source
Register or log in to add new notes.