instance method
delete_by
Ruby on Rails 7.2.3
Since v6.0.6Signature
delete_by(*args)
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)
Parameters
-
argsrest
Source
# File activerecord/lib/active_record/relation.rb, line 1122
def delete_by(*args)
where(*args).delete_all
end
Defined in activerecord/lib/active_record/relation.rb line 1122
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::Relation