diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2004-12-17 21:36:13 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2004-12-17 21:36:13 +0000 |
commit | 648b8fda54e5de742e4ffbb4bc8e6edf0b68a111 (patch) | |
tree | 6a827db4b218a2f0ff8e8680c0d340470eb07832 /activerecord/lib | |
parent | cf78e736d29a60693eb9997d2c2678ae5d72cb1b (diff) | |
download | rails-648b8fda54e5de742e4ffbb4bc8e6edf0b68a111.tar.gz rails-648b8fda54e5de742e4ffbb4bc8e6edf0b68a111.tar.bz2 rails-648b8fda54e5de742e4ffbb4bc8e6edf0b68a111.zip |
Added Base.destroy and Base.delete to remove records without holding a reference to them first.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@206 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib')
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index ca586aacad..2bcea9dd5d 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -333,6 +333,16 @@ module ActiveRecord #:nodoc: object end + # Deletes the record with the given +id+ without instantiating an object first. + def delete(id) + delete_all([ "#{primary_key} = ?", id ]) + end + + # Destroys the record with the given +id+ by instantiating the object and calling #destroy (all the callbacks are the triggered). + def destroy(id) + find(id).destroy + end + # Updates all records with the SET-part of an SQL update statement in +updates+. A subset of the records can be selected # by specifying +conditions+. Example: # Billing.update_all "category = 'authorized', approved = 1", "author = 'David'" |