module ViewModel::AfterTransactionRunner

def add_to_transaction

def add_to_transaction
  if connection.transaction_open?
    connection.add_transaction_record(self)
  else
    before_commit
    after_commit
  end
end

def after_commit; end

def after_commit; end

def after_rollback; end

def after_rollback; end

def before_commit; end

def before_commit; end

def before_committed!

def before_committed!
  before_commit
end

def committed!(*)

Rails' internal API
def committed!(*)
  after_commit
end

def connection

Override to tie to a specific connection.
def connection
  ActiveRecord::Base.connection
end

def rolledback!(*)

def rolledback!(*)
  after_rollback
end

def run_commit_callbacks_on_first_saved_instances_in_transaction

the last valid callback.
behavior that doesn't require so many inapplicable heuristics to identify
model interface here such as #destroyed?, so we'll lock in the older
the new behaviour would require implementing more of the ActiveRecord
equivalent AfterTransactionRunners for the same callback, and opting into
and delegates to Rails configuration. For us, we don't expect multiple
ActiveRecord models, this class method is defined on ActiveRecord::Core
hook on the first equivalent instance to be enqueued or the last one. For
Rails 7.1+ expects after transaction hooks to declare whether to run the
def run_commit_callbacks_on_first_saved_instances_in_transaction
  true
end

def trigger_transactional_callbacks?

def trigger_transactional_callbacks?
  true
end