cakephp 查找所有条件 AND OR
以下是我的情况:
'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)
),
),
当我调试查询时,它会出现这样的情况,这是错误的:
AND ((`EventCompetitor`.`is_black` = 0) AND (`EventCompetitor`.`is_adult` = 0)) AND
现在,这不是我想要的,我想要这样的结果:
((`EventCompetitor`.`is_black` = 1) AND (`EventCompetitor`.`is_adult` = 1)) OR ((`EventCompetitor`.`is_black` = 0) AND (`EventCompetitor`.`is_adult` = 0))
任何想法,我怎样才能实现它?
谢谢 !
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 !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
“OR”键控数组中的子键具有相同的名称,第二个键有效地覆盖第一个键。您需要将这些“AND”条件封装在它们自己的数组中,以防止按键冲突。
例如。而不是:
做:
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:
do:
我还没有测试过它,但我认为你需要以下内容:
AND
隐含在条件之间,你只需要定义OR
组I haven't tested it, but I think you need the following:
AND
is implied between conditions, you only have to defineOR
groups我认为你需要一个额外的 array() 在那里,我不确定,但值得一试:
I think you need an extra array() in there, im not sure but its worth a try: