Skip to content

docs: add transaction side-effect recipes#10153

Open
memleakd wants to merge 1 commit intocodeigniter4:4.8from
memleakd:feat/transaction-side-effect-docs
Open

docs: add transaction side-effect recipes#10153
memleakd wants to merge 1 commit intocodeigniter4:4.8from
memleakd:feat/transaction-side-effect-docs

Conversation

@memleakd
Copy link
Copy Markdown
Contributor

@memleakd memleakd commented May 2, 2026

Description

This PR proposes adding practical documentation for deferring side effects with database transaction callbacks.

It expands the transaction callback docs with examples for:

  • using afterCommit() for side effects that should only run after committed data is visible
  • using afterRollback() for cleanup that should only run when a transaction does not commit
  • avoiding assumptions that Model callbacks are automatically commit-aware

Motivation

The afterCommit() and afterRollback() APIs are useful for avoiding subtle consistency issues around database transactions.

For example, application code may need to dispatch a job, trigger an event, clear a cache entry, send a notification, or clean up a temporary file. If that work runs before the surrounding transaction finishes, it may observe data that is not committed yet, or it may run even though the transaction later rolls back.

This documentation gives users a small set of copyable recipes for those cases.

Checklist

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

- explain why external side effects should be deferred until commit
- add afterCommit and afterRollback examples
- clarify Model callbacks are not commit-aware by themselves

Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
@github-actions github-actions Bot added documentation Pull requests for documentation only 4.8 PRs that target the `4.8` branch. labels May 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.8 PRs that target the `4.8` branch. documentation Pull requests for documentation only

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant