这是我获取随机产品的查询:
public function getRelatedProducts()
{
$em = $this->getDoctrine()->getManager();
$max = $em->createQuery('SELECT MAX(p.id) FROM GlassShopBundle:Product p')->getSingleScalarResult();
return $em->createQuery('SELECT q FROM GreenMonkeyDevGlassShopBundle:Product p WHERE p.id >= :rand ORDER BY p.id ASC')
->setParameter('rand',rand(0,$max))
->setMaxResults(1)
->getSingleResult()
->getResults();
}
我收到一个Undefined method 'getRelatedByCategory'. The method name must start with either findBy or findOneBy!
错误,这对我来说很奇怪,因为其他查询对我有用,而且我并没有真正偏离。有什么想法吗?