Issues replacing deprecated orWhere


I’m trying to replace some uses of orWhere but I’ve quickly stepped onto some issues.

This is a minor one. It’s easy to create a QE object with AND, but a lot more verbose with OR. The only ways I know is $expr = $query->newExpr(); $expr->setConjuction('or'); or new \Cake\Database\Expression([], [], 'or'); . Am I correct? I’d like to know before filling my code with lines like these.

The following code fails because it thinks I’m using a callable:
$q->where(function ($exp, $query) { return $query->newExpr()->or([$exp, '1=2']); });

I’m trying to add more conditions with an OR with the following code and the error is the same:
$q->where(function ($exp, $query) { return $query->newExpr()->or([$query->clause('where'), '1=2']); });

If I swap the order in the array the process enters an infinite loop:
$q->where(function ($exp, $query) { return $query->newExpr()->or(['1=2', $query->clause('where')]); });

How could I solve these issues?

For OR conditions, I usually build up an array with all of them, then use ->where(['OR' => $conditions]).

Right. I’ve done that many times but after reading the documentation for CakePHP4 I thought there could be another way using objects.

Thanks for replying.