How to return object from a DQL query?

时光怂恿深爱的人放手 提交于 2019-12-04 09:51:41
J0HN

You are fetching only position column from DB. Try replacing select('r.position') with select(r). See DQL reference

If you need objects with only position attribute, refer to partial objects

The: $qb->getResult(\Doctrine\ORM\Query::HYDRATE_OBJECT);

Return an array with object and you can catch them with: $match[0];

If you want to return a single result you must be use: $qb->getOneOrNullResult()

I could not solve my problem with your solution, here my part of code:

$qb = $this->_objectManager->createQuery('Select d from Hotbed\Entity\Department d where d.id <> :id and d.title = :title');
        $qb->setParameters(array('id' => $context['id'], 'title' => $value));
        $match = $qb->getResult(\Doctrine\ORM\Query::HYDRATE_OBJECT);

$match returns this:

array(1) {
 [0] => object(Hotbed\Entity\Department)#626 (4) {
   ['inputFilter':protected] =&gt; NULL
   ['id':protected] =&gt; int(25)
   ['title':protected] => string(4) '2222'
   ['state':protected] => int(0)
 }
}

thx for any help

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!