Module: ActiveRecord::Persistence

Defined in:
ext/active_record/persistence.rb

Overview

Active Record Persistence

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

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.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'ext/active_record/persistence.rb', line 31

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



46
47
48
49
50
51
52
53
54
# File 'ext/active_record/persistence.rb', line 46

def update!(attributes)
  @no_save_transaction = true
  with_transaction_returning_status do
    assign_attributes(attributes)
    save!
  end
ensure
  @no_save_transaction = false
end