-1

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?

dsuma
  • 1,000
  • 2
  • 9
  • 30
  • 1
    method named `getRelatedProducts`, you call `getRelatedByCategory` so whats the problem? – Alexey B. Jul 01 '13 at 05:35
  • 1
    Just a related thing: It moans at you about "findBy" and "findOneBy" because of what's called "magic finders" in Doctrine. The "magic finders" are handled in a PHP __call function, where you end up when you call inaccessible or nonexistent methods. That message could use a change to be less misleading... – Radu C Jul 01 '13 at 20:24

1 Answers1

1

Possible that is a typo in called function name. Method named getRelatedProducts, you call getRelatedByCategory.

Alexey B.
  • 11,965
  • 2
  • 49
  • 73