aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/callbacks.rb
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2008-08-14 01:21:58 +0200
committerXavier Noria <fxn@hashref.com>2008-08-14 01:22:44 +0200
commit37054e6eb57a1ebe330f31323d25355ff3069cb5 (patch)
tree9531c9c2b3da1e6f470929819831f68233bff61b /activerecord/lib/active_record/callbacks.rb
parentfcdf8e2988cdc16b4a8b3ecdd15e401c819c846e (diff)
downloadrails-37054e6eb57a1ebe330f31323d25355ff3069cb5.tar.gz
rails-37054e6eb57a1ebe330f31323d25355ff3069cb5.tar.bz2
rails-37054e6eb57a1ebe330f31323d25355ff3069cb5.zip
documented how to trigger rollbacks within the callback chain, and related gotchas
Diffstat (limited to 'activerecord/lib/active_record/callbacks.rb')
-rw-r--r--activerecord/lib/active_record/callbacks.rb11
1 files changed, 10 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/callbacks.rb b/activerecord/lib/active_record/callbacks.rb
index 9f3b0765ca..f1983b6496 100644
--- a/activerecord/lib/active_record/callbacks.rb
+++ b/activerecord/lib/active_record/callbacks.rb
@@ -172,7 +172,16 @@ module ActiveRecord
#
# == Transactions
#
- # The entire callback chain for +save+ and +destroy+ runs within their transaction.
+ # The entire callback chain for +save+ and +destroy+ runs within their transaction, including
+ # the <tt>after_*</tt> hooks. Cancellation does not trigger a rollback. To rollback
+ # the transaction just raise an exception the same way you do for regular transactions.
+ #
+ # Note though that such an exception bypasses the regular call chain in Active Record:
+ # If ActiveRecord::Rollback is raised both +save+ and +destroy+ return +nil+. On the other
+ # hand <tt>save!</tt> does *not* raise ActiveRecord::RecordNotSaved, and does not raise
+ # anything else for that matter, <tt>save!</tt> just returns +nil+ in that case.
+ # If any other exception is raised it goes up until it reaches the caller, no matter
+ # which one of the three actions was being performed.
module Callbacks
CALLBACKS = %w(
after_find after_initialize before_save after_save before_create after_create before_update after_update before_validation