diff options
author | Hongli Lai (Phusion <hongli@phusion.nl> | 2008-09-21 23:01:32 +0200 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2008-09-21 22:53:44 +0100 |
commit | 46939a9b5a0098fddeac99a8a4331f66bdd0710e (patch) | |
tree | 8e233668c2bac790bd54b50d664f813903f199f6 /activerecord/lib/active_record/base.rb | |
parent | 5f83e1844c83c19cf97c6415b943c6ec3cb4bb06 (diff) | |
download | rails-46939a9b5a0098fddeac99a8a4331f66bdd0710e.tar.gz rails-46939a9b5a0098fddeac99a8a4331f66bdd0710e.tar.bz2 rails-46939a9b5a0098fddeac99a8a4331f66bdd0710e.zip |
Add Model#delete instance method, similar to Model.delete class method. [#1086 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'activerecord/lib/active_record/base.rb')
-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 b20da512eb..3aa8e5541d 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -2306,6 +2306,16 @@ module ActiveRecord #:nodoc: # Deletes the record in the database and freezes this instance to reflect that no changes should # be made (since they can't be persisted). + # + # Unlike #destroy, this method doesn't run any +before_delete+ and +after_delete+ + # callbacks, nor will it enforce any association +:dependent+ rules. + def delete + self.class.delete(id) unless new_record? + freeze + end + + # Deletes the record in the database and freezes this instance to reflect that no changes should + # be made (since they can't be persisted). def destroy unless new_record? connection.delete <<-end_sql, "#{self.class.name} Destroy" |