【发布时间】:2021-03-01 10:02:41
【问题描述】:
我在通过 Symfony 存储库查询我的数据库时遇到问题。 如果我不指定存储库
/**
* ProductsText
*
* @ORM\Table(name="products_text")
* @ORM\Entity
*/
我可以像这样使用 Doctrine 选择我的数据库之一:
->getRepository(ProductsText::class, "db1").
但如果我声明存储库:
/**
* ProductsText
*
* @ORM\Table(name="products_text")
* @ORM\Entity(repositoryClass="App\Repository\Product\ProductsTextRepository")
*/
它只选择我从中提取实体的数据库。 我不能使用两个不同的实体,因为用户在登录时选择了“数据库”。不幸的是,我也不能合并这两个数据库,因为它们不是多租户的。
我的猜测是,我可以通过将注册表从存储库中保留来解决问题。不幸的是,我之前的尝试以前端不再加载而告终。
有效,但仅适用于一个数据库:
class ProductsTextRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, ProductsText::class);
}
没用:
class TbProductsTextRepository
{
/**
* @var EntityRepository
*/
private $repository;
public function __construct(EntityManagerInterface $entityManager)
{
$this->repository = $entityManager->getRepository(TbProductsText::class);
}
很遗憾,我不了解如何重新生成存储库的机制。
我用:
- Symfony 5.2
- 教义 2.2
- 学说 ORM 2.8
- Doctrine Migrations Bundle 3.0
【问题讨论】:
-
我已经读过了。这也不是问题。但是使用我有特定查询的存储库。
标签: doctrine-orm doctrine