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

  1. Place the transaction boundary in the service layer, not in the controller.
  2. Group related changes and flush once, inside wrapInTransaction().
  3. Pick the concurrency strategy: #[ORM\Version] optimistic locking for edits, PESSIMISTIC_WRITE for short critical sections.
  4. Handle OptimisticLockException and constraint violations explicitly.
  5. After a rollback, clear the EntityManager and re-fetch what you still need.
Installs
81
GitHub Stars
224
First Seen
Sep 17, 2026