Skip to content

Automatic entity manager flush method call during ES projection reset #409

@lifinsky

Description

@lifinsky

Description
For some projections, it is convenient to use the doctrine entity manager instead of low-level inserts or updates (using dbal connection). But in this case, without calling the flush method, the projection can not be restored after reset, but calling flush explicitly duplicates the transaction block during the synchronous operation of the projection using command handler, especially since there can be several synchronous projections for one event.

Example

   /**
     * @throws OptimisticLockException
     * @throws ORMException
     */
    #[EventHandler]
    public function onCardWasClosed(CardWasClosed $event): void
    {
        /** @var Card $card */
        $card = $this->entityManager->find(Card::class, (string) $event->id);
        $card->markAsClosed($event->closedAt());
        $this->entityManager->flush(); // redundant during command handler
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions