doctrine-transactions
Installation
SKILL.md
Doctrine Transactions (Symfony)
Use when
- Several writes must succeed or fail together.
- Two users or workers can edit the same row concurrently.
- Deciding where to flush and who owns the transaction boundary.
- Recovering after a failed flush, a constraint violation, or a lost connection.
Default workflow
- Place the transaction boundary in the service layer, not in the controller.
- Group related changes and flush once, inside
wrapInTransaction(). - Pick the concurrency strategy:
#[ORM\Version]optimistic locking for edits,PESSIMISTIC_WRITEfor short critical sections. - Handle
OptimisticLockExceptionand constraint violations explicitly. - After a rollback, clear the EntityManager and re-fetch what you still need.