我有一个具有多对多连接的实体:
- 实体 - 主要对象
- 客户 - 通过“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.
任何人都可以帮忙吗?