Pergunta

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);
}
Foi útil?

Solução

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

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top