class method self.delete

Ruby on Rails 2.2.3

Since v2.2.3 Last seen in v2.3.18

Available in: v2.2.3 v2.3.18

Signature

self.delete(id)

Delete an object (or multiple objects) where the id given matches the primary_key. A SQL DELETE command is executed on the database which means that no callbacks are fired off running this. This is an efficient method of deleting records that don’t need cleaning up after or other actions to be taken.

Objects are not instantiated with this method, and so :dependent rules defined on associations are not honered.

Parameters

  • id - Can be either an Integer or an Array of Integers.

Examples

# Delete a single object
Todo.delete(1)

# Delete multiple objects
todos = [1,2,3]
Todo.delete(todos)

Parameters

id req
Source
# File activerecord/lib/active_record/base.rb, line 744
      def delete(id)
        delete_all([ "#{connection.quote_column_name(primary_key)} IN (?)", id ])
      end

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

Defined in ActiveRecord::Base

Type at least 2 characters to search.

↑↓ navigate · open · esc close