method

delete

rails latest stable - Class: ActiveRecord::Relation

Method not available on this version

This method is only available on newer versions. The first available version (v3.0.0) is shown here.

delete(id_or_array)
public

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])