我在原则 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
)
)
我希望结果返回一组 Racesobjects这样我就可以访问与该对象关联的方法(我很确定以前版本的 Doctrine 默认返回对象)。
I tried:
$aRaces = $query->getResult(Query::HYDRATE_OBJECT);
但这并没有什么区别。
感谢您的帮助
你只取position
来自数据库的列。尝试更换select('r.position')
with select(r)
. See DQL 参考 https://www.doctrine-project.org/projects/doctrine-orm/en/latest/reference/dql-doctrine-query-language.html
如果你需要的对象只有position
属性,参考部分对象 https://www.doctrine-project.org/projects/doctrine-orm/en/latest/reference/partial-objects.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)