cakephp OR condition

后端 未结 3 1957
失恋的感觉
失恋的感觉 2021-01-07 21:22

Originaly posted on cakephp Q&A but i\'ll put it up here in hope of getting some answers.

I have a bunch of companies that has a status of 0 as default but somet

相关标签:
3条回答
  • 2021-01-07 22:13

    You can also fetch record by using following method: put values in an array e.g. $arr=array(1,2);

     $res = $this->Model->find('all', array(                      
            'conditions' =>array('Model.filedname'=>$arr),
            'model.id' => 'desc'
      ));
    

    I hope you will find answer.

    0 讨论(0)
  • 2021-01-07 22:15

    I'm not sure to have understood what results you expect. If you want to retrieve all records having status = 0, plus let's say the one having status = 3, you could use an 'IN' instead of an 'OR'.

    In Cake, you would write it like this:

    $status = 3;
    $conditions = array('Company.status' => array(0, $status));
    
    0 讨论(0)
  • 2021-01-07 22:19

    Try

    'Company' => array (
        'conditions' =>  array (
            'OR' => array(
                array('Company.status' => 0),
                array('Company.status' => $status),
            )
    
        )
    )
    

    In the cookbook it says to wrap the or conditions in arrays if they are pertaining to the same field http://book.cakephp.org/2.0/en/models/retrieving-your-data.html#complex-find-conditions

    0 讨论(0)
提交回复
热议问题