diff options
author | Sven Fuchs <svenfuchs@artweb-design.de> | 2008-08-25 11:11:08 +0200 |
---|---|---|
committer | Sven Fuchs <svenfuchs@artweb-design.de> | 2008-08-25 11:11:08 +0200 |
commit | e464f9b6b93daa847a7d6fa1c3af63c8cef3f3e2 (patch) | |
tree | 6fcd3b1a2c30a2c25b85915af5a4277765f26858 /activerecord/lib/active_record/transactions.rb | |
parent | 90a9637d41016c0d230ba36657e83a4f8d54cc46 (diff) | |
parent | fb20d6f09d5e91280bf2b5888a7299b50dba7a7b (diff) | |
download | rails-e464f9b6b93daa847a7d6fa1c3af63c8cef3f3e2.tar.gz rails-e464f9b6b93daa847a7d6fa1c3af63c8cef3f3e2.tar.bz2 rails-e464f9b6b93daa847a7d6fa1c3af63c8cef3f3e2.zip |
Merge commit 'rails/master' into i18n
Diffstat (limited to 'activerecord/lib/active_record/transactions.rb')
-rw-r--r-- | activerecord/lib/active_record/transactions.rb | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/transactions.rb b/activerecord/lib/active_record/transactions.rb index 0531afbb52..81462a2917 100644 --- a/activerecord/lib/active_record/transactions.rb +++ b/activerecord/lib/active_record/transactions.rb @@ -91,11 +91,11 @@ module ActiveRecord end def destroy_with_transactions #:nodoc: - transaction { destroy_without_transactions } + with_transaction_returning_status(:destroy_without_transactions) end def save_with_transactions(perform_validation = true) #:nodoc: - rollback_active_record_state! { transaction { save_without_transactions(perform_validation) } } + rollback_active_record_state! { with_transaction_returning_status(:save_without_transactions, perform_validation) } end def save_with_transactions! #:nodoc: @@ -118,5 +118,17 @@ module ActiveRecord end raise end + + # Executes +method+ within a transaction and captures its return value as a + # status flag. If the status is true the transaction is committed, otherwise + # a ROLLBACK is issued. In any case the status flag is returned. + def with_transaction_returning_status(method, *args) + status = nil + transaction do + status = send(method, *args) + raise ActiveRecord::Rollback unless status + end + status + end end end |