adr/2022_03_24_remove_flush_from_handlers.md
When working with entities and persisting the current state to DB one has to call a flush method on entity manager. By default, it starts and commits transactions to used DB. The other possibility is to start the transaction manually, which will suspend the auto-commit feature of Doctrine.
Using flush() in command handlers can cause problems with inconsistent DB states if the end-user decides to adjust models definitions. Implicitly flushing will commit all the changes queued up so far, which may lead to DB error or committing not consistent data. What is more, we would need an additional feature that would allow adjusting the entity's state before the transaction will close.
Manual setting up of transactions around handlers clearly defines their boundaries. Even tho this may still lead to DB error or committing not consistent data, setting boundaries outside of our code improves DX greatly, as an adjustment on objects may be made with decorator pattern outside of predefined handler.
Chosen option: "Flushing outside of handlers with the manually triggered transaction"
It is the most straightforward solution which will suspend the auto-commit feature of Doctrine and gives us more control and flexibility when working with data.