Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lifinsky opened this issue Nov 13, 2024 · 0 comments
Open

Comments

@lifinsky
Copy link
Contributor

lifinsky commented Nov 13, 2024

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
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant