How transactions work between ActiveRecord and Sequel
masterThe extension synchronizes the transaction state between Sequel and ActiveRecord. This allows you to nest transactions from both libraries seamlessly.
Key behaviors:
DB.in_transaction?will returntrueif an ActiveRecord transaction is currently open.- Sequel's transaction API (including
isolationlevels andsavepoints) is fully supported. - Transaction hooks like
after_commitare managed to ensure they execute correctly relative to the outer transaction state.
ActiveRecord::Base.transaction do
DB.in_transaction? #=> true
end
# Using Sequel's API within an ActiveRecord transaction
DB.transaction(isolation: :serializable) do
DB.after_commit { ... }
DB.transaction(savepoint: true) do
DB.after_commit(savepoint: true) { ... }
end
end