Method: ActiveRecord::Relation#delete_by
- Defined in:
- activerecord/lib/active_record/relation.rb
#delete_by(*args) ⇒ Object
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)
1119 1120 1121 |
# File 'activerecord/lib/active_record/relation.rb', line 1119 def delete_by(*args) where(*args).delete_all end |