2014-09-09 1 views
0

symfonyproject에 다음 스크립트가 있습니다.find() 대 createQuery

use Rowoco\AllgemeinBundle\Entity\Place; 
. 
. 

public function getPlacelist($iduser) 
{ 
    $em = $this->getDoctrine()->getManager(); 
    $request = Request::createFromGlobals(); 

    $placeRepo = $em->getRepository("RowocoAllgemeinBundle:Place"); 
    $placeEntity = $placeRepo->findBy(
     array(), 
     array(), 
     $request->request->get("limitCount"), 
     $request->request->get("limitStart") 
    ); 
    //return $placeEntity; 

    $q = $em 
     ->createQuery("SELECT p.description 
          FROM RowocoAllgemeinBundle:Place p 
          "); 
    return $q->getResult(); 

} 

나는 특별한 저장소가 없습니다. 하지만 findby()를 사용할 때, 결과를 얻지 못한다. createQuery를 사용할 때 결과로 2 행을 얻었습니다.

코드에서 오류를 어디에서 찾을 수 있습니까?

+1

코드에서 findBy()에 조건이 없습니다. 모든 결과를 가져오고 findBy() 대신 findAll()을 사용하려는 경우에 조건이 있습니다. –

답변

1

findBy이처럼 키/값의 배열을 기대 : 마지막 항목에서 볼 수 있듯이

array(
    'id' => 5, 
    'name' => 'john', 
    'friends' => array(1,23) 
); 

하면, 당신은 또한 WHERE … IN() 쿼리의 effed을 가지고 배열을 전달할 수 있습니다. 당신이 할 수없는 것은 (AFAIK) findBy에 전달할 수있는 범위와 복잡한 패턴입니다.

+0

은 find ($ limitCount, $ limitStart, ORDER)를 사용할 수 있습니다. 하나의 행으로 정렬 된 모든 행이 필요합니다. –

+1

'find'와'findBy'가 완전히 다른 경우,'find'는 정확히 하나의 엔티티 객체를 검색하는 슈퍼 - 바로 가기입니다. – lxg

+1

힌트 : Symfony로 작업하고 있지만, ORM과 관련된 자료를 조사하기 위해 Doctrine 문서를 사용해야합니다. 예를 들어, findBy 항목에 대한 설명은 다음과 같습니다. http://docs.doctrine-project.org/en/2.0.x/reference/working-with-objects.html#by-simple-conditions – lxg

관련 문제