Complex query complex query cakephp multiple condition "OR"

I want to make such a request using cakephp:

WHERE text LIKE '%keyword%' AND ( (text LIKE '%something%') OR (text LIKE '%something%') OR (...) ) AND ( (text LIKE '%other%') OR (text LIKE '%other%') OR (...) ) NOT ( (text LIKE '%dont include%') OR (text LIKE '%dont include%') OR (...) ) 

this is my code for $ conditions:

 $conditions = array ( 'Tweet.text LIKE' => '%keyword%', 'AND' => array( array( 'OR' => array( // topic array('Tweet.text LIKE' => '%something%'), array('Tweet.text LIKE' => '%something%') ) ), array( 'OR' => array( // sentiment array('Tweet.text LIKE' => '%other%'), array('Tweet.text LIKE' => '%other%') ) ) ), 'NOT' => array( array('Tweet.text LIKE' => '%dont include%'), array('Tweet.text LIKE' => '%dont include%') ) ); 

I show the result using the Debugger :: dump () method, and the result simply uses the last OR condition, not both the OR conditions:

 array( 'Tweet.text LIKE' => '%keyword%', 'OR' => array( (int) 0 => array( 'Tweet.text LIKE' => '%other%' ), (int) 1 => array( 'Tweet.text LIKE' => '%other%' ) ), 'NOT' => array( (int) 0 => array( 'Tweet.text LIKE' => '%dont include%' ), (int) 1 => array( 'Tweet.text LIKE' => '%dont include%' ) ) ) 

My question is: how can I make the request use the "OR" condition?

Pls reply as soon as possible .. Thanks in advance :)

+4
source share
1 answer

Try the following:

 $conditions = array( 'Tweet.text LIKE' => '%aa%', //implied and array( //implied and 'or' => array( array('Tweet.text LIKE' => '%11%'), array('Tweet.text LIKE' => '%22%'), array('Tweet.text LIKE' => '%33%'), ... ) ), array( //implied and 'or' => array( array('Tweet.text LIKE' => '%123%'), array('Tweet.text LIKE' => '%456%'), array('Tweet.text LIKE' => '%789%'), ... ) ) 'not' => array( 'or' => array( array('Tweet.text LIKE' => '%x%'), array('Tweet.text LIKE' => '%y%'), array('Tweet.text LIKE' => '%z%'), ... ) ) ) 

will be

 text LIKE aa AND ( either 11, 22, 33 ) AND (either 123, 456, 789) BUT NOT (x || y || z)` 

Any array that does not indicate or , and or not is equal to and . No need to specify it manually.

+11
source

All Articles