未找到查询结果,尽管至少需要一行
2022-08-30 18:02:56
我有以下代码:
/**
* Search similar category given a string
*
* @param $searchTerm search similar category
*/
public function findOneSimilarCategory($searchTerm)
{
$query = $this->createQueryBuilder('secondLevelCategory')
->select('secondLevelCategory')
->where('secondLevelCategory.categoryTitle LIKE :searchTerm')
->setParameter('searchTerm', $searchTerm)
->getQuery();
$query->useResultCache(true, self::CACHE_RESULT_LIFETIME, md5(__METHOD__ . serialize('category-search-' . $query->getParameters())));
$query->useQueryCache(true);
return $query->getSingleResult();
}
但是这给了我一个错误:
"PHP message: PHP Fatal error: Uncaught exception 'Doctrine\ORM\NoResultException' with message 'No result was found for query although at least one row was expected.' in /var/www/Shopious/vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php:649