我在请求中抛出NonUniqueResultException有问题
public function getLastViewUpdate($view)
{
$qb = $this->getEntityManager()->createQueryBuilder();
$result = $qb->select('vu')
->from('EasyApp\ApplicationBundle\Entity\ViewUpdate', 'vu')
->where('vu.view = :view')
->orderBy('vu.date','DESC')
->setParameter('view', $view)
->getQuery()
->getSingleResult();
return $result;
}
但是我不知道为什么,也许我必须导入一些东西,但是我找不到
CRITICAL - Uncaught PHP Exception Doctrine\ORM\NonUniqueResultException: "" at /Users/antoine/Documents/projects/easyApp/application/vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php line 621
谢谢你的帮助
您可以检查getSingleResult
功能的声明
/**
* Gets the single result of the query.
*
* Enforces the presence as well as the uniqueness of the result.
*
* If the result is not unique, a NonUniqueResultException is thrown.
* If there is no result, a NoResultException is thrown.
*
* @param integer $hydrationMode
* @return mixed
* @throws NonUniqueResultException If the query result is not unique.
* @throws NoResultException If the query returned no result.
*/
public function getSingleResult($hydrationMode = null)
{
...
if (count($result) > 1) {
throw new NonUniqueResultException;
}
...
}
解决此问题您可以设置使用LIMIT
来查询并仅获得一个结果->setMaxResults(1)
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句