Module: Activerecord::Transactionable

Extended by:
ActiveSupport::Concern
Defined in:
lib/activerecord/transactionable.rb,
lib/activerecord/transactionable/result.rb,
lib/activerecord/transactionable/version.rb

Overview

SRP: Provides an example of correct behavior for wrapping transactions. NOTE: Rails’ transactions are per-database connection, not per-model, nor per-instance,

see: http://api.rubyonrails.org/classes/ActiveRecord/Transactions/ClassMethods.html

Defined Under Namespace

Modules: ClassMethods Classes: Result

Constant Summary collapse

DEFAULT_ERRORS_TO_HANDLE_INSIDE_TRANSACTION =
[]
DEFAULT_ERRORS_PREPARE_ON_SELF_INSIDE =
[]
DEFAULT_ERRORS_TO_HANDLE_OUTSIDE_TRANSACTION =
[ ActiveRecord::RecordInvalid ]
DEFAULT_ERRORS_PREPARE_ON_SELF_OUTSIDE =
[ ActiveRecord::RecordInvalid ]
ERRORS_TO_DISALLOW_INSIDE_TRANSACTION =

These errors (and possibly others) will invalidate the transaction (on PostgreSQL and possibly other databases). This means that if you did rescue them inside a transaction (or a nested transaction) all subsequent queries would fail.

[
    ActiveRecord::RecordInvalid,
    ActiveRecord::StatementInvalid,
    ActiveRecord::RecordNotUnique
].freeze
TRANSACTION_METHOD_ARG_NAMES =
[
    :requires_new,
    :isolation,
    :joinable
].freeze
REQUIRES_NEW =
INSIDE_TRANSACTION_ERROR_HANDLERS =
[
    :rescued_errors,
    :prepared_errors,
    :retriable_errors,
    :reraisable_errors
].freeze
OUTSIDE_TRANSACTION_ERROR_HANDLERS =
[
    :outside_rescued_errors,
    :outside_prepared_errors,
    :outside_retriable_errors,
    :outside_reraisable_errors
].freeze
INSIDE_CONTEXT =
"inside".freeze
OUTSIDE_CONTEXT =
"outside".freeze
VERSION =
"2.0.1"

Instance Method Summary collapse

Instance Method Details

#transaction_wrapper(**args) ⇒ Object



51
52
53
54
55
# File 'lib/activerecord/transactionable.rb', line 51

def transaction_wrapper(**args)
  self.class.transaction_wrapper(object: self, **args) do
    yield
  end
end