2017-12-09 7 views
1

ID 배열 (idExam)이 있습니다.맞춤 저장소 Symfony

그리고 모든 ID를 추가하는 사용자 지정 리포지토리를 만들고 싶습니다.

이이 내 코드

:

public function examNotValidated($idExam) 
{ 
    return $this->createQueryBuilder('q') 
     ->where('q.creadetby = :creadetby and q.id = :idExam') 
     ->setParameter('creadetby', false) 
     ->setParameter('idExam', $idExam) 
     ->getQuery() 
     ->getResult(); 
} 

그리고 난 이런 식으로 뭔가 싶습니다

public function examNotValidated($idExam) 
{ 
    return $this->createQueryBuilder('q') 
     ->where('q.creadetby = :creadetby and (q.id = :idExams[0] or q.id = :idExams[1] or q.id = :idExams[3])') 
     ->setParameter('creadetby', false) 
     ->setParameter('idExams', $idExams) 
     ->getQuery() 
     ->getResult(); 
} 

그렇게 어쨌든 거기를? q.id = : idExams [0] 또는 q.id = idExams [1] 또는 q.id = 예 (반대의 논리 여기

public function examNotValidated(array $ids) 
{ 
    $qb = $this->createQueryBuilder('q'); 
    return $qb->where('q.creadetby = :creadetby') 
     ->andWhere($qb->expr()->in('q.id', $ids)) 
     ->setParameter('creadetby', false) 
     ->getQuery() 
     ->getResult(); 
} 

된다

답변

2

IN 식을 사용할 수있다 : idExams [3])

public function examNotValidated(array $ids) 
{ 
    $qb = $this->createQueryBuilder('q'); 

    $orX = $qb->expr()->orX(); 
    foreach ($ids as $id) { 
     $orX->add('q.id = '.$id); 
    } 

    return $qb->where('q.creadetby = :creadetby') 
     ->andWhere($orX); 
     ->setParameter('creadetby', false) 
     ->getQuery() 
     ->getResult(); 
}