-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
EntityManagerDecorator's repositories use EntityManager #5820
Comments
Hello, I'm afraid this is not something we can fix. Since we're talking about decorator pattern, inner EM instance has no knowledge about being decorated. One possible solution would be using RepositoryFactory that is created for your decorator, not for inner EM by default. |
Just to give people reading this a well visible notice. There is a similar issue to this one with |
The difference is that #7161 can workaround it, while this one cannot |
I think event objects will also have the inner EM (as well as any place receiving the EM from the EM itself as |
Actually it does have a workaround: class CustomDecorator extends EntityManagerDecorator {
protected $repositoryFactory;
// In Symfony 2.* $config can be injected with @doctrine.orm.default_configuration
public function __construct(EntityManagerInterface $wrapped, Configuration $config)
{
$this->repositoryFactory = $config->getRepositoryFactory();
parent::__construct($wrapped);
}
/**
* Gets the repository for an entity class.
*
* Fixes: https://github.com/doctrine/doctrine2/issues/5820
*
* @param string $entityName The name of the entity.
*
* @return \Doctrine\ORM\EntityRepository The repository class.
*/
public function getRepository($entityName)
{
return $this->repositoryFactory->getRepository($this, $entityName);
}
} |
And then you find that SQLBuilder also has a wrapped entity manager instance, you fix that, only to find that all collections also have the wrapped instance embedded. In the end, there is no point in using a decorated entity manager because of that because it's impossible to make it work. |
Any workaround for getting the decorator in lifecycle callbacks? |
|
Repositories created by
Doctrine\ORM\Decorator\EntityManagerDecorator
useEntityManager
instead ofEntityManagerDecorator
:This behavior may be unexpected for custom repositories using decorator object.
The text was updated successfully, but these errors were encountered: