duanfan5012
2018-05-31 10:05
浏览 57
已采纳

如何使用Symfony QueryBuilder检索实体ID?

I'm trying to personalize a symfony 2.4 repository query to retrieve only some fields. Everything is ok with flat fields but when retrieving Entity fields, I only get the id (by default) but not the whole entity data. My query:

    $select = $this->createQueryBuilder('ca')
    ->select('ca.id, ca.name')
    ->leftJoin('ca.users', 'user')
    ->addSelect('(user) as users'); 

    $select->setMaxResults($count);

    return $select->getQuery()->getResult();

The result is: [{id: 1, name: "Some name", users: 1}, ...]

How can I change this query for users to contain the whole user data, like id, name, address, etc.?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

4条回答 默认 最新

相关推荐 更多相似问题