-1
創建查詢我有對實體許多一對多連接:如何選擇多對多元素
- 實體 - 主要對象
- 客戶 - 有很多一對多通過與實體「entity_clients」 表
配置使用.yml
manyToMany:
clients:
targetEntity: Client
joinTable:
name: entity_clients
joinColumns:
taskpack_id:
referencedColumnName: id
inverseJoinColumns:
client_id:
referencedColumnName: id
我有實體元素,我想獲得查詢客戶端附加到它。 客戶我可以選擇:
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('TestGroupBundle:Entity')->find($id);
$clients = $entity->getClients();
但我需要查詢如何選擇這個元素。我試着寫查詢,但沒有像這樣:
$qb = $this->em->createQueryBuilder()
->select('c')
->from('TestGroupBundle:Entity', 't')
->join('t.clients', 'c')
->andWhere('t.id = :id')
->setParameter('id', $id);
,但我得到的錯誤:
[Semantical Error] line 0, col -1 near 'SELECT c FROM': Error: Cannot select entity through identification variables without choosing at least one root entity alias.
誰能幫助?