如何写cakephp和和或查询

时间:2015-03-05 12:41:34

标签: php cakephp cakephp-2.0 cakephp-1.3 cakephp-2.3

 $tmp_sales    = $this->tmp_sale->find('all', array(
                'conditions' => array(
                    array(
                        'no' => $no,
                        'barcode' => $barcode,'employee' => $emp, 'store' => $store_name
                    )
                )
            ));

这是我目前的查询。

select * from tmp_sale where  no = '$no' and 
                       'employee' ='$emp' and  store = '$store_name' and ( barcode='$barcode' or name='$barcode')

我想像上面那样做出改变。如何在cakephp

中编写这样的查询

2 个答案:

答案 0 :(得分:1)

'conditions' => array(
    'no' => $no,
    'employee' => $emp,
    'store '=> $store_name,
    'OR' => array(
        array('barcode' => $barcode),
        array('name' => $barcode)
    )
)

答案 1 :(得分:-2)

  

Cakephp模型名称应为单数,tmp_sale模型名称应替换为TmpSale名称。 cakephp的查询如下所示。   你应该试试这个

 $tmp_sales = $this->TmpSale->find('all', array(
            'conditions' => array( 'no' => $no,
                    'employee' => $emp,
                    'store '=>$store_name,
                    'or'=>array('barcode'=>$barcode,
                        'name'=>$barcode)

            )
        ));

由于