-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.
谁能帮助?