Skip to content

Commit

Permalink
revises the rdoc of update_attributes and update_attributes! to docum…
Browse files Browse the repository at this point in the history
…ent they are wrapped in a transaction, and adds code comments explaining why
  • Loading branch information
fxn committed Jul 14, 2010
1 parent 684fb5e commit b7944e1
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions activerecord/lib/active_record/persistence.rb
Expand Up @@ -118,18 +118,23 @@ def update_attribute(name, value)
self.class.update_all(changes, { primary_key => self[primary_key] }) == 1 self.class.update_all(changes, { primary_key => self[primary_key] }) == 1
end end


# Updates all the attributes from the passed-in Hash and saves the record. # Updates the attributes of the model from the passed-in hash and saves the
# If the object is invalid, the saving will fail and false will be returned. # record, all wrapped in a transaction. If the object is invalid, the saving
# will fail and false will be returned.
def update_attributes(attributes) 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 with_transaction_returning_status do
self.attributes = attributes self.attributes = attributes
save save
end end
end end


# Updates an object just like Base.update_attributes but calls save! instead # 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. # of +save+, so an exception is raised if the record is invalid.
def update_attributes!(attributes) 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 with_transaction_returning_status do
self.attributes = attributes self.attributes = attributes
save! save!
Expand Down

0 comments on commit b7944e1

Please sign in to comment.