【发布时间】:2019-07-01 05:09:45
【问题描述】:
我想要的很简单,我想用 querybuilder 将查询的特定字段与别名在 3 个不同级别的关系中分组,更清楚地说,我有 3 个相关表,consulta(医疗咨询),paciente(pacient) ,医生(医生),usuario(用户),所以我在查询中得到的所有内容都是医疗咨询及其患者数据,加上医生数据及其相关用户数据,我想要的是省略那些相关的不相关字段表,我使用 addSelect 来包含关系级别之间的所有数据,但我得到的是所有字段,我想检索“paciente”表的特定字段,以及用户表(这是用户相关医生的),我将展示该计划的方式:
Consulta :{
// omit the other fields
{paciente: name and last name}
{doctor: { usuario: name and last name}}}
$queryBuilder = $em->getRepository('MedicoBundle:Consulta')
->createQueryBuilder('e')
->leftJoin('e.paciente', 'a')
->addSelect('a')
->leftJoin('e.doctor', 'o')
->addSelect('o')
->leftJoin('o.usuario', 'u')
->addSelect('u')
->where('e.fecha =:fecha')
->orderBy('e.id', 'ASC')
->setParameter('fecha', $fecha)
->getQuery();
它检索所有还不错的字段,但我想检索其中一些字段并省略其他字段,如我在方案中显示的那样
【问题讨论】: