aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorMarcel Molina <marcel@vernix.org>2007-12-05 15:14:40 +0000
committerMarcel Molina <marcel@vernix.org>2007-12-05 15:14:40 +0000
commited69b38afaa5a4703864dc007399ab05613bb5d2 (patch)
tree370de400a8b60c082e9faf822f849e0c43274194 /activerecord/lib/active_record
parent4f1d353b186ef01526a7b2a4117e869906571568 (diff)
downloadrails-ed69b38afaa5a4703864dc007399ab05613bb5d2.tar.gz
rails-ed69b38afaa5a4703864dc007399ab05613bb5d2.tar.bz2
rails-ed69b38afaa5a4703864dc007399ab05613bb5d2.zip
Document options and add examples for destroy. Closes #7988 [fearoffish]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8291 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record')
-rwxr-xr-xactiverecord/lib/active_record/base.rb21
1 files changed, 19 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 0935af40fb..7e2d93202f 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -515,8 +515,25 @@ module ActiveRecord #:nodoc:
delete_all([ "#{connection.quote_column_name(primary_key)} IN (?)", id ])
end
- # Destroys the record with the given +id+ by instantiating the object and calling #destroy (all the callbacks are the triggered).
- # If an array of ids is provided, all of them are destroyed.
+ # Destroy an object (or multiple objects) that has the given id, the object is instantiated first,
+ # therefore all callbacks and filters are fired off before the object is deleted. This method is
+ # less efficient than ActiveRecord#delete but allows cleanup methods and other actions to be run.
+ #
+ # This essentially finds the object (or multiple objects) with the given id, creates a new object
+ # from the attributes, and then calls destroy on it.
+ #
+ # ==== Options
+ #
+ # +id+ Can be either an Integer or an Array of Integers
+ #
+ # ==== Examples
+ #
+ # # Destroy a single object
+ # Todo.destroy(1)
+ #
+ # # Destroy multiple objects
+ # todos = [1,2,3]
+ # Todo.destroy(todos)
def destroy(id)
id.is_a?(Array) ? id.each { |id| destroy(id) } : find(id).destroy
end