aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/persistence.rb
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2010-07-14 17:42:48 +0200
committerXavier Noria <fxn@hashref.com>2010-07-14 17:42:57 +0200
commitb7944e1b211c37fd9db8d72bef9f12c42b68a0a4 (patch)
treefaa691e809e9267d29f02944263d2a6bfdda0fcd /activerecord/lib/active_record/persistence.rb
parent684fb5e7d50801edcf20eceaa465259602871e9c (diff)
downloadrails-b7944e1b211c37fd9db8d72bef9f12c42b68a0a4.tar.gz
rails-b7944e1b211c37fd9db8d72bef9f12c42b68a0a4.tar.bz2
rails-b7944e1b211c37fd9db8d72bef9f12c42b68a0a4.zip
revises the rdoc of update_attributes and update_attributes! to document they are wrapped in a transaction, and adds code comments explaining why
Diffstat (limited to 'activerecord/lib/active_record/persistence.rb')
-rw-r--r--activerecord/lib/active_record/persistence.rb13
1 files changed, 9 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb
index 3681a63e03..7ec443ccc7 100644
--- a/activerecord/lib/active_record/persistence.rb
+++ b/activerecord/lib/active_record/persistence.rb
@@ -118,18 +118,23 @@ module ActiveRecord
self.class.update_all(changes, { primary_key => self[primary_key] }) == 1
end
- # Updates all the attributes from the passed-in Hash and saves the record.
- # If the object is invalid, the saving will fail and false will be returned.
+ # Updates the attributes of the model from the passed-in hash and saves the
+ # record, all wrapped in a transaction. If the object is invalid, the saving
+ # will fail and false will be returned.
def update_attributes(attributes)
+ # The following transaction covers any possible database side-effects of the
+ # attributes assignment. For example, setting the IDs of a child collection.
with_transaction_returning_status do
self.attributes = attributes
save
end
end
- # Updates an object just like Base.update_attributes but calls save! instead
- # of save so an exception is raised if the record is invalid.
+ # Updates its receiver just like +update_attributes+ but calls <tt>save!</tt> instead
+ # of +save+, so an exception is raised if the record is invalid.
def update_attributes!(attributes)
+ # The following transaction covers any possible database side-effects of the
+ # attributes assignment. For example, setting the IDs of a child collection.
with_transaction_returning_status do
self.attributes = attributes
save!