문제

In Doctrine, when building a query with QueryBuilder, does the first whereclause have to be defined with $qb->where()or can I use $qb->andWhere() directly. For example, is this valid:

$qb->select('Mystuff\Entity\User','u');
$qb->andWhere('usertype = :usertype');
$qb->andWhere('usercategory = :usercategory');

Or, as a more relevant example:

$filter = array('usertype'=>'basic','usercategory'=>'business');
$qb->select('Mystuff\Entity\User','u');
foreach ($filter as $fkey => $fval) {
   $qb->andWhere($fkey.' = :'.$fval);
}
도움이 되었습니까?

해결책

Yes that will work. where() deletes any other criteria before adding those submitted, while andWhere() appends to an AND expression with any existing criteria.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top