edge badge
Namespace
Methods
A
R
T
W
Constants
ACTIONS = [:create, :destroy, :update]
 
CALLBACK_WARN_MESSAGE = "Currently, Active Record suppresses errors raised " \ "within `after_rollback`/`after_commit` callbacks and only print them to " \ "the logs. In the next version, these errors will no longer be suppressed. " \ "Instead, the errors will propagate normally just like in other Active " \ "Record callbacks.\n" \ "\n" \ "You can opt into the new behavior and remove this warning by setting:\n" \ "\n" \ " config.active_record.raise_in_transactional_callbacks = true"
 
Instance Public methods
add_to_transaction()

Add the record to the current transaction so that the after_rollback and after_commit callbacks can be called.

# File activerecord/lib/active_record/transactions.rb, line 328
def add_to_transaction
  if self.class.connection.add_transaction_record(self)
    remember_transaction_record_state
  end
end
rollback_active_record_state!()

Reset id and @new_record if the transaction rolls back.

# File activerecord/lib/active_record/transactions.rb, line 297
def rollback_active_record_state!
  remember_transaction_record_state
  yield
rescue Exception
  restore_transaction_record_state
  raise
ensure
  clear_transaction_record_state
end
transaction(options = {}, &block)

See ActiveRecord::Transactions::ClassMethods for detailed documentation.

# File activerecord/lib/active_record/transactions.rb, line 274
def transaction(options = {}, &block)
  self.class.transaction(options, &block)
end
with_transaction_returning_status()

Executes method within a transaction and captures its return value as a status flag. If the status is true the transaction is committed, otherwise a ROLLBACK is issued. In any case the status flag is returned.

This method is available within the context of an ActiveRecord::Base instance.

# File activerecord/lib/active_record/transactions.rb, line 340
def with_transaction_returning_status
  status = nil
  self.class.transaction do
    add_to_transaction
    begin
      status = yield
    rescue ActiveRecord::Rollback
      clear_transaction_record_state
      status = nil
    end

    raise ActiveRecord::Rollback unless status
  end
  status
end