instance method
destroy_by
Ruby on Rails 8.0.4
Since v6.0.6Signature
destroy_by(*args)
Finds and destroys all records matching the specified conditions. This is short-hand for relation.where(condition).destroy_all. Returns the collection of objects that were destroyed.
If no record is found, returns empty array.
Person.destroy_by(id: 13)
Person.destroy_by(name: 'Spartacus', rating: 4)
Person.destroy_by("published_at < ?", 2.weeks.ago)
Parameters
-
argsrest
Source
# File activerecord/lib/active_record/relation.rb, line 1116
def destroy_by(*args)
where(*args).destroy_all
end
Defined in activerecord/lib/active_record/relation.rb line 1116
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::Relation