instance method delete

Ruby on Rails 6.1.7.10

Since v5.2.8.1 Last seen in v7.1.6

Available in: v5.2.8.1 v6.0.6 v6.1.7.10 v7.0.10 v7.1.6

Signature

delete(id_or_array)

Deletes the row with a primary key matching the id argument, using an 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.

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

id_or_array req
Source
# File activerecord/lib/active_record/persistence.rb, line 351
      def delete(id_or_array)
        delete_by(primary_key => id_or_array)
      end

Defined in activerecord/lib/active_record/persistence.rb line 351 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveRecord::Persistence::ClassMethods

Type at least 2 characters to search.

↑↓ navigate · open · esc close