我在 Doctrine 2 中编写了一个 DQL 查询:
$qb->select('r.position')
->from('\Entities\Races', 'r')
->where($qb->expr()->eq('r.entrantId', ':entrant_id'))
->setParameter('entrant_id', $this->entrantId);
$query = $qb->getQuery();
$aRaces = $query->getResult();
目前它以数组形式返回查询结果,如下所示:
Array
(
[0] => Array
(
[position] => 10
)
[1] => Array
(
[position] => 4
)
)
我希望结果返回一个 Races对象数组,以便我可以访问与该对象关联的方法(我很确定以前版本的 Doctrine 默认返回对象)。
我试过了:
$aRaces = $query->getResult(Query::HYDRATE_OBJECT);
但这并没有什么不同。
感谢帮助