I am setting up an App with multiple databases, each database has its own entity manager.
When I query the data and specify the entity manager for the entity, it works fine.
I cannot create a form that has a relationship (both entities use the same entity manager).
I get the following error when trying to render a form to create a new entity
[Semantical Error] Couldn't find constant App\Repository\Admin\Item\ItemsRepository, class App\Entity\Item\Items.
// App/Entity/Item/Items.php
/**
* Items
*
* @ORM\Entity(repositoryClass=App\Repository\Admin\Item\ItemsRepository)
* @ORM\Table(name="items")
* @ORM\Entity
*/
class Items
{
....
}
// App/Repository/Item/ItemsRepository.php
namespace App\Repository\Admin\Item;
use App\Entity\Item\Items;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @method Items|null find($id, $lockMode = null, $lockVersion = null)
* @method Items|null findOneBy(array $criteria, array $orderBy = null)
* @method Items[] findAll()
* @method Items[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class ItemsRepository extends ServiceEntityRepository
{
...
}
#config/package/doctrine.yaml
orm:
default_entity_manager: default
entity_managers:
default:
connection: default
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity/Default'
prefix: 'App\Entity\Default'
item_service:
connection: item_service
mappings:
ItemAlias:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity/Item'
prefix: 'App\Entity\Item'
alias: ItemAlias
Overall file structure:
src
Controller
Admin
Item
UnitConversionsController.php
Entity
Item
Items.php
Repository
Admin
Item
ItemsRepository.php
I'd be happy if there was a way to manually define the entity manager that the Type class is using to pull the related data for populating the form.
How do I get symfony to recognize a default entity manager for a directory of entities?