class method
self.delete
Ruby on Rails 2.3.18
Since v2.2.3 Last seen in v2.3.18Available in: v2.2.3 v2.3.18
Signature
self.delete(id)
Deletes the row with a primary key matching the id argument, using a SQL DELETE statement, and returns the number of rows deleted. Active Record objects are not instantiated, so the object’s callbacks are not executed, including any :dependent association options or Observer methods.
You can delete multiple rows at once by passing an Array of ids.
Note: Although it is often much faster than the alternative, #destroy, skipping callbacks might bypass business logic in your application that ensures referential integrity or performs other essential jobs.
Examples
# Delete a single row Todo.delete(1) # Delete multiple rows Todo.delete([2,3,4])
Parameters
-
idreq
Source
# File activerecord/lib/active_record/base.rb, line 779
def delete(id)
delete_all([ "#{connection.quote_column_name(primary_key)} IN (?)", id ])
end
Defined in activerecord/lib/active_record/base.rb line 779
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::Base