2014-06-16 2 views
1

Doctrine \ ODM \ MongoDB \ DocumentRepository 유형의 개체가 있고 데이터를 가져 오는 방법을 변경해야하지만 이제는 $ this-> findby를 사용하지만 뭔가가 필요합니다. 더 복잡하고 교리 쿼리를 사용하고 싶습니다.Doctrine ODM MongoDB DocumentRepository에서 doctrine 쿼리 만들기

모두 examples Doctrine \ ODM \ MongoDB \ DocumentRepository 인스턴스 내에서 createQuery를 호출하는 방법을 알지 못하고 EntityManager를 필요로하는 것 같습니다. $ this-> getEntityManager 함수는 없습니다.

class definition에는 entitymanager를 가져 오는 방법이 누락 된 것처럼 보입니다.

는 엔티티 관리자를 얻을 수있는 방법이있을 수 있습니다 A A querybuilder 만드는 방법 ($ this->을 createQueryBuilder())와 that있다 그러나 이것은 다른 쿼리 빌더의 유형이어야합니다 :

$this->createQueryBuilder()->getEntityManager() 정의되지 않은 방법 : getEntityManager. 이름이 쿼리 작성자임을 제안하지만 실제로는 그렇지 않습니다.

Doctrine \ ODM \ MongoDB \ DocumentRepository에서 dql을 실행할 방법이 있습니까? 나는 날짜가 아닌 날짜 필드에서 검색해야하기 때문에

[업데이트]

그 이유는. 3 개의 문자열 필드 (연도, 4 길이 문자열, 월, 2 길이 문자열 및 일, 2 길이 문자열)로 구성됩니다. 현재 날짜가 월요일이면 토요일과 일요일을 검색해야합니다. 현재 버그 코드는 findby 쿼리를 사용하고 때로는이 같은 것을 생산 : 나 같은 쿼리를 수행 할 수있는 무언가를 제공하지 않는 것

Where 
    type = 6 
    and (
    (year='2014' and month='06' and day='02') 
    OR (year='2014' and month='06' and day='01') 
    OR (year='2014' and month='05' and day='31') 
) 

findby :

$this->findBy(array(
     'data.type; => 6, 
     'data.year' => '2014', 
     'data.month' => '06', 
     'data.day' => array('$in' => ['02','01','0-1']) 
//results in: where year=''2014' and month='06' and day in ('02','01','0-1') 

내가 좋아하는 뭔가를해야합니다. 당신이 $this->createQueryBuilder('MyEntity')에서 제공하는 것 쿼리 빌더 객체를 사용할 수있을 것 같은

답변

3

http://doctrine-mongodb-odm.readthedocs.org/en/latest/reference/query-builder-api.html

는 것 같습니다. 이 같은 것을 시도하십시오

$qb = $this->createQueryBuilder('data'); 

$results = $qb 
    ->field('type')->equals(6) //add quotes i.e. '6' if type is string 
    ->addOr(
     $qb->expr() 
     ->field('year')->equals('2014') 
     ->field('month')->equals('06') 
     ->field('day')->in(array('01','02')) 
    ) 
    ->addOr(
     $qb->expr() 
     ->field('year')->equals('2014') 
     ->field('month')->equals('05') 
     ->field('day')->equals('31') 
    )->getQuery()->execute(); 
+0

당신의 코멘트를 주셔서 감사합니다, 아직도 문제가 조금있다. 질의는'type = 6 and ((year = '2014'and month = '06 'and day = '01') 또는 OR (year = '2014'and ...' 6 또는 [{ "년": "2014", "월": "06", "일": "01"}, { "년": "2014", ... 그래서 유형 6 – HMR

+0

@HMR이'type = 6'을 포함하도록 업데이트되었습니다. – FuzzyTree

+0

고맙습니다. 저에게 유형 6의 레코드 만 나오면 고맙겠습니다.하지만 그것을 줄 것입니다. 내일 시도해보십시오. 실패 할 경우 where 함수를 호출하여 JavaScript로 전달할 수 있습니다. – HMR

관련 문제