Below is my condition:
'OR' =>
array(
'AND' => array(
array('EventCompetitor.is_black' => 1),
array('EventCompetitor.is_adult' => 1)
),
'AND' => array(
array('EventCompetitor.is_black' => 0),
array('EventCompetitor.is_adult' => 0)
),
),
When I debug my query, it comes something like this, which is wrong:
AND ((`EventCompetitor`.`is_black` = 0) AND (`EventCompetitor`.`is_adult` = 0)) AND
Now, that's not what I want, I want it something like this:
((`EventCompetitor`.`is_black` = 1) AND (`EventCompetitor`.`is_adult` = 1)) OR ((`EventCompetitor`.`is_black` = 0) AND (`EventCompetitor`.`is_adult` = 0))
Any idea, how can I achieve it?
Thanks !
your subkeys in your "OR" keyed array are the same name, with the second key effectively overwriting the first. you need to encapsulate those "AND" conditions in their own arrays, to prevent the key collision.
eg. instead of:
'OR' =>
array(
'AND' => array(
array('EventCompetitor.is_black' => 1),
array('EventCompetitor.is_adult' => 1)
),
'AND' => array(
array('EventCompetitor.is_black' => 0),
array('EventCompetitor.is_adult' => 0)
),
),
do:
'OR' =>
array(
array('AND' => array(
array('EventCompetitor.is_black' => 1),
array('EventCompetitor.is_adult' => 1)
)),
array('AND' => array(
array('EventCompetitor.is_black' => 0),
array('EventCompetitor.is_adult' => 0)
)),
),
I haven't tested it, but I think you need the following:
'OR' =>
array(
array(
array('EventCompetitor.is_black' => 1),
array('EventCompetitor.is_adult' => 1)
),
array(
array('EventCompetitor.is_black' => 0),
array('EventCompetitor.is_adult' => 0)
)
)
AND
is implied between conditions, you only have to define OR
groups
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With