123456789_123456789_123456789_123456789_123456789_

Module: ActiveRecord::Transactions

Relationships & Source Files
Namespace Children
Modules:
Extension / Inclusion / Inheritance Descendants
Included In:
Base, ActiveRecord::InternalMetadata, ActiveRecord::SchemaMigration
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Defined in: activerecord/lib/active_record/transactions.rb

Overview

See ClassMethods for documentation.

Class Method Summary

::ActiveSupport::Concern - Extended

class_methods

Define class methods from given block.

included

Evaluate given block in context of base class, so that you can write class macros here.

prepended

Evaluate given block in context of base class, so that you can write class macros here.

Instance Method Summary

DSL Calls

included

[ GitHub ]


10
11
12
13
14
# File 'activerecord/lib/active_record/transactions.rb', line 10

included do
  define_callbacks :commit, :rollback,
                   :before_commit,
                   scope: [:kind, :name]
end

Instance Method Details

#transaction(**options, &block)

See Transactions::ClassMethods for detailed documentation.

[ GitHub ]

  
# File 'activerecord/lib/active_record/transactions.rb', line 289

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 Base instance.

[ GitHub ]

  
# File 'activerecord/lib/active_record/transactions.rb', line 345

def with_transaction_returning_status
  status = nil
  connection = self.class.connection
  ensure_finalize = !connection.transaction_open?

  connection.transaction do
    add_to_transaction(ensure_finalize || has_transactional_callbacks?)
    remember_transaction_record_state

    status = yield
    raise ActiveRecord::Rollback unless status
  end
  status
end