Cake php multiply Find Conditions OR / AND

时间:2015-04-01 13:54:43

标签: cakephp find conditional-statements findall

嘿伙计们,我一直在努力解决这个问题。我试图从使用cakephp的表中选择所有例如 我想从一个表中选择所有(A == 1 AND B == 2)OR(A == 2和B == 1),只需查询 这是我到目前为止的代码

$conditions =  array("OR"=>
array("Message.to_to"=>$daddy["User"]["id"],
           "Message.from_from"=>$this->Auth->user("id")),
array("Message.to_to"=>$this->Auth->user("id"),
          "Message.from_from"=>$daddy["User"]["id"])
                                                       );

1 个答案:

答案 0 :(得分:0)

要获得预期结果(A == 1 AND B == 2)或(A == 2和B == 1),请尝试嵌套'和'您的代码中目前缺少的条件。

您还需要指定conditions参数。

尝试以下方法:

$conditions = array(
   'conditions' => array(
     "or"=> array(
            "and" => array(
                   "Message.to_to"=>$daddy["User"]["id"],
                   "Message.from_from"=>$this->Auth->user("id"),
                   ),
            "and" => array(
                   "Message.to_to"=>$this->Auth->user("id"),
                   "Message.from_from"=>$daddy["User"]["id"],
                   ),
       ),
    ),
 );

参考:http://book.cakephp.org/2.0/en/models/retrieving-your-data.html