Skip to content

Commit

Permalink
Rewrite ActiveRecord::Base.delete docs for clarity, and mention retur…
Browse files Browse the repository at this point in the history
…n value
  • Loading branch information
chrisk committed Dec 27, 2008
1 parent fa6218c commit 1ea13fc
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions activerecord/lib/active_record/base.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -756,25 +756,26 @@ def update(id, attributes)
end end
end end


# Delete an object (or multiple objects) where the +id+ given matches the primary_key. A SQL +DELETE+ command # Deletes the row with a primary key matching the +id+ argument, using a
# is executed on the database which means that no callbacks are fired off running this. This is an efficient method # SQL +DELETE+ statement, and returns the number of rows deleted. Active
# of deleting records that don't need cleaning up after or other actions to be taken. # Record objects are not instantiated, so the object's callbacks are not
# executed, including any <tt>:dependent</tt> association options or
# Observer methods.
# #
# Objects are _not_ instantiated with this method, and so +:dependent+ rules # You can delete multiple rows at once by passing an Array of <tt>id</tt>s.
# defined on associations are not honered.
# #
# ==== Parameters # Careful: although it is often much faster than the alternative,
# # <tt>#destroy</tt>, skipping callbacks might bypass business logic in
# * +id+ - Can be either an Integer or an Array of Integers. # your application that ensures referential integrity or performs other
# essential jobs.
# #
# ==== Examples # ==== Examples
# #
# # Delete a single object # # Delete a single row
# Todo.delete(1) # Todo.delete(1)
# #
# # Delete multiple objects # # Delete multiple rows
# todos = [1,2,3] # Todo.delete([2,3,4])
# Todo.delete(todos)
def delete(id) def delete(id)
delete_all([ "#{connection.quote_column_name(primary_key)} IN (?)", id ]) delete_all([ "#{connection.quote_column_name(primary_key)} IN (?)", id ])
end end
Expand Down

0 comments on commit 1ea13fc

Please sign in to comment.