Module: ActiveRecord::Persistence
- Defined in:
- ext/active_record/persistence.rb,
ext/active_record/associations/collection_association.rb
Overview
Active Record Persistence
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#update(attributes) ⇒ Object
Updates the attributes of the model from the passed-in hash and saves the record, all wrapped in a transaction.
- #update!(attributes) ⇒ Object
Instance Method Details
#update(attributes) ⇒ Object
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.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'ext/active_record/associations/collection_association.rb', line 80 def update(attributes) @updating = :updating Thread.current[:sunstone_updating_model] = self # 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 assign_attributes(attributes) save end ensure @updating = false Thread.current[:sunstone_updating_model] = nil end |
#update!(attributes) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'ext/active_record/persistence.rb', line 21 def update!(attributes) @no_save_transaction = true with_transaction_returning_status do assign_attributes(attributes) save! end ensure @no_save_transaction = false end |