This is my query for getting a random product:
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();
}
I get a Undefined method 'getRelatedByCategory'. The method name must start with either findBy or findOneBy!
Error, which to me is strange since other queries hav worked for me and I have not really deviated. Any thoughts?
Possible that is a typo in called function name. Method named getRelatedProducts
, you call getRelatedByCategory
.