mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
EntityManagerDecorator::transactional injects wrapped EM into closure #5935
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Isinlor on GitHub (Mar 28, 2018).
In
\Doctrine\ORM\Decorator\EntityManagerDecorator::transactional:The method is passing
$funcintowrapped.However,
$functakes entity manager as an argument and therefore we get raw entity manger in$func.Related issue: https://github.com/doctrine/doctrine2/issues/5820
@stof commented on GitHub (Apr 27, 2018):
that's the issue with any API passing
$thisto some other code. As soon as your pass yourselves to some other code, decorators won't have effect at this point (as$thisis the inner object).@stof commented on GitHub (Apr 27, 2018):
btw, here is a workaround: don't use the argument, but the EM you already have:
@stof commented on GitHub (Apr 27, 2018):
there is a way to solve it for EntityManagerDecorator: wrap the callable into another callable, and call the original callable with the decorator as argument instead
@Isinlor commented on GitHub (Apr 27, 2018):
The direct issue I had was with loading fixtures by \Doctrine\Common\DataFixtures\Executor\ORMExecutor::execute
So, I can't pass EM there by myself.
My workaround was adding this to my decorator:
@bramcordie commented on GitHub (Dec 20, 2023):
Hey @Isinlor!
After upgrading to Symfony 5 this workaround was causing some problems because the
transactionalmethod has been deprecated in favor ofwrapInTransaction. What I ended up doing in a customEntityManagerDecoratoris this:@stof commented on GitHub (Dec 20, 2023):
@bramcordie this is broken though: you are disabling the transaction wrapping...
@bramcordie commented on GitHub (Dec 20, 2023):
@stof, I thought this was what you were hinting at in this earlier comment: https://github.com/doctrine/orm/issues/7161#issuecomment-385008923
I think I missed a step but can you give an example of what you meant or an alternative approach?
@stof commented on GitHub (Dec 20, 2023):
@bramcordie commented on GitHub (Dec 20, 2023):
Thanks a lot for the example, works like a charm!