diff options
author | Xavier Noria <fxn@hashref.com> | 2009-02-01 11:13:27 +0100 |
---|---|---|
committer | Michael Koziarski <michael@koziarski.com> | 2009-02-22 15:31:27 +1300 |
commit | fc09ebc669bd58f415f7d3ef932ef02dab821ab5 (patch) | |
tree | 368512c146b1931f08eeb964fd20b79f26945710 /activerecord/lib/active_record/transactions.rb | |
parent | f4391c362d71efbc6d9cb66ab0aadc0593b7679e (diff) | |
download | rails-fc09ebc669bd58f415f7d3ef932ef02dab821ab5.tar.gz rails-fc09ebc669bd58f415f7d3ef932ef02dab821ab5.tar.bz2 rails-fc09ebc669bd58f415f7d3ef932ef02dab821ab5.zip |
Wrap calls to update_attributes in a transaction.
Signed-off-by: Michael Koziarski <michael@koziarski.com>
[#922 state:committed]
Diffstat (limited to 'activerecord/lib/active_record/transactions.rb')
-rw-r--r-- | activerecord/lib/active_record/transactions.rb | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/transactions.rb b/activerecord/lib/active_record/transactions.rb index 0b6e52c79b..9eabe7172b 100644 --- a/activerecord/lib/active_record/transactions.rb +++ b/activerecord/lib/active_record/transactions.rb @@ -10,7 +10,7 @@ module ActiveRecord base.extend(ClassMethods) base.class_eval do - [:destroy, :save, :save!].each do |method| + [:destroy, :save, :save!, :update_attribute, :update_attributes, :update_attributes!].each do |method| alias_method_chain method, :transactions end end @@ -200,6 +200,20 @@ module ActiveRecord rollback_active_record_state! { self.class.transaction { save_without_transactions! } } end + def update_attribute_with_transactions(name, value) + with_transaction_returning_status(:update_attribute_without_transactions, name, value) + end + + def update_attributes_with_transactions(attributes) + with_transaction_returning_status(:update_attributes_without_transactions, attributes) + end + + def update_attributes_with_transactions!(attributes) + transaction do + update_attributes_without_transactions!(attributes) + end + end + # Reset id and @new_record if the transaction rolls back. def rollback_active_record_state! id_present = has_attribute?(self.class.primary_key) |