0
我有一个存储库,我需要使用另一个持有不同连接的实体管理器。这个例子是不行的,因为$this->getEntityManager('anotherConnection')
得到它使用当前仓库同一经理:单个存储库中的多个实体管理器
class BlahRepository extends \Doctrine\ORM\EntityRepository
{
public function find($id)
{
$qb = $this->createQueryBuilder('a')
->select('a')
->where('a.id = :id')
->setParameter('id', $id);
$result = $qb->getQuery()->getResult();
$repositoryFromAnotherManager = $this->getEntityManager('anotherConnection')
->getRepository('Bundle:Entity');
foreach ($result as $value) {
$something = $repositoryFromAnotherManager->getTranslatedSomething($value->getSomething());
$value->setTranslatedSomething($something);
}
return $result;
}
}
我的问题是:是否有可能获得其持有仓库等有关的其他实体管理器。注意:此库不是通过注入来调用的,因此在services.yml中更改getRepository
工厂不是解决方案。
我认为你最好的选择是制作一个自定义服务并将两个存储库注入它。我能想到的唯一的另一种方式是覆盖原则库工厂服务。你可以搜索如何做到这一点。 – Cerad
我想我会使用服务,谢谢 – Eimsas