Anastasia Sitnina
Anastasia Sitnina

Reputation: 625

Doctrine query builber: a problem adding multiple conditions with andWhere

I have a number of conditions:

if (!empty($requestData['year'])) {
                    $conditions[] = $qb->expr()->eq('dd.year', $requestData['year']);
}
if(!empty($requestData['month'])){
                    $conditions[] = $qb->expr()->eq('dd.month', $this->convertMonthStringToNumber($requestData['month']));
}

Which I am trying to add to the andWhere. I have found this solution:

$andX = $qb->expr()->andX();
$andX->addMultiple($conditions);
$qb->andWhere($andX);

But this throws me an error:

assert($lookahead !== null)
in [SERVER]\vendor\doctrine\orm\src\Query\Parser.php (line 2639) 

Upvotes: 1

Views: 53

Answers (1)

Mesolaries
Mesolaries

Reputation: 335

Try this:

$andX = $qb->expr()->andX(...$conditions);
$qb->andWhere($andX);

Upvotes: 1

Related Questions