Reputation: 55
I have a problem querying my database via Symfony Repository. If I don't specify a repository
/**
* ProductsText
*
* @ORM\Table(name="products_text")
* @ORM\Entity
*/
i can select one of my databases by using Doctrine like this:
->getRepository(ProductsText::class, "db1").
But if i declare the repository:
/**
* ProductsText
*
* @ORM\Table(name="products_text")
* @ORM\Entity(repositoryClass="App\Repository\Product\ProductsTextRepository")
*/
It only selects the database from which I pulled the entity from. I can't use two different entities because the user selects the "database" when logging in. Unfortunately, I can't merge the two databases yet either, as they are not multi-tenant.
My guess is that I can solve the problem by keeping the registry from the repository in general. My previous attempts unfortunately ended up with the front end no longer loading.
Works, but only for one database:
class ProductsTextRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, ProductsText::class);
}
Did not works:
class TbProductsTextRepository
{
/**
* @var EntityRepository
*/
private $repository;
public function __construct(EntityManagerInterface $entityManager)
{
$this->repository = $entityManager->getRepository(TbProductsText::class);
}
Unfortunately, I don't understand the mechanics of how the repositorys are regestrated.
I use:
Upvotes: 0
Views: 994
Reputation: 55
I solved the problem by not "registering" the repository. By using EntityRepository and without a construct, I can use the repository for both databases.
use Doctrine\ORM\EntityRepository;
class TbProductsTextRepository extends EntityRepository
{
Upvotes: 1