Combining and / or operators in Phalcon \ Mvc \ Model \ Criteria

I just write my first phalcon application and ask a question to filter the request using Phalcon \ Mvc \ Model \ Criteria.

Finally, I want a query like this

SELECT * FROM table WHERE status = 'A' AND ( title LIKE 'combining%' OR title LIKE 'phalcon%' OR ( title LIKE 'criteria%' AND title LIKE '%phalcon' ) ) 

For me, there seems to be no way of parentheses in the criteria for a model of Falcons. The only way to achieve this is to write phql.

Instead of writing full phql, I can probably write something like this, but it gets the same complexity

 <?php $query = Table::query(); $query->where('status = :status:', array('status' => 'A')); $query->andWhere('( title LIKE :title1: OR title LIKE :title2: OR ( title LIKE :title3: AND title LIKE :title4: ) )', array( 'title1' => 'combining%', 'title2' => 'phalcon%', 'title3' => 'criteria%', 'title4' => '%phalcon' )); 
+5
source share
1 answer

It seems that the criteria "where", "and where" and "or where" will add external brackets for you, then you can manually write an internal bracket.

 $query = Model::query() ->where('status = "A"') ->andWhere('title LIKE "combining%" OR title LIKE "phalcon%" OR ( title LIKE "criteria%" AND title LIKE "%phalcon" ) '); $models = $query->execute(); 

You can check the correctness of the where clause.

 var_dump($query->getWhere()); 
0
source

All Articles