Module: ActiveRecord::Persistence
- Defined in:
- ext/active_record/persistence.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.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'ext/active_record/persistence.rb', line 26 def update(attributes) @sunstone_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 @sunstone_updating = false Thread.current[:sunstone_updating_model] = nil end |
#update!(attributes) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'ext/active_record/persistence.rb', line 41 def update!(attributes) @no_save_transaction = true with_transaction_returning_status do assign_attributes(attributes) save! end ensure @no_save_transaction = false end |