我正在尝试优化查询,因为我需要一个简单的列表作为隶属于多个实体的实体。所以我创建了这个查询,你应该把 id 和 name 还给我:
public function findAllOrderByName() {
$qb = $this->createQueryBuilder('a');
$query = $qb->select(array('partial a.{id,name}'))
->addOrderBy('a.name', 'ASC')
->getQuery();
return $query->getResult();
}
像这样在控制器中返回它:
public function getInstrumentsAction()
{
$instruments = $this->getDoctrine()->getRepository('AcmeInstrumentBundle:Instrument')->findAllOrderByName();
return array('instruments' => $instruments);
}
而不是只给我两个阵营,给我完整的对象,从而包括其他相关实体的所有领域。
为什么它不起作用?