Query expressions add new with AND and OR


#1

I try to create and chain expression with different conjunction, but it seems I do not undertood how does it work.

$e = new QueryExpression();
$e->add(['OR' => '1=2']);
$e->add($e->and_('3=4'));
$e->add($e->or_('5=6'));
$e->add(['AND' => '7=8']);

The result of the abode is (1=2 AND 3=4 AND 5=6 AND 7=8)

Ho do I add AND and OR conjunctions?


#2

there was orWhere() and andWhere() which I was use
https://book.cakephp.org/3.0/en/orm/query-builder.html#advanced-conditions

but there is also info that they are deprecated.


#3

The way I found is that you have to create a new QueryExpression for every part of it

$query->newExpr()
    ->eq(1, 2)
    ->add(
        $query->newExpr('3 = 4')
            ->add($query->newExpr()->eq(5, 6))
            ->setConjunction('OR')
    )
    ->add($query->newExpr('7 = 8');