2013-07-01 2 views
-1

Symfony2에서 사용자 정의 쿼리 액세스이 임의의 제품 점점 내 쿼리입니다 : 저장소

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! 오류를 얻을하고 정말하지 않은 이탈. 이견있는 사람?

+1

'getRelatedProducts'라는 메소드는'getRelatedByCategory'를 호출하여 문제가 무엇입니까? –

+1

관련성이 높은 것 : Doctrine에서 "마법 발견 자"라고 불리는 이유로 "findBy"및 "findOneBy"에 대해 당신에게 신음합니다. "마법 탐지기"는 접근 할 수 없거나 존재하지 않는 메소드를 호출 할 때 PHP __call 함수에서 처리됩니다. 그 메시지는 잘못된 것을 덜어주기 위해 변화를 사용할 수 있습니다 ... –

답변

1

가능한 함수 이름은 오타입니다. 방법이 getRelatedProducts 인 경우 getRelatedByCategory으로 전화하십시오.