简体   繁体   English

如何编写cakephp和和或查询

[英]how to write cakephp and and or query

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

This is my present query. 这是我目前的查询。

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

I want to make change like above . 我想像上面那样进行更改。 how to write query like this in cakephp 如何在cakephp中写这样的查询

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

Cakephp Model name should be Singular, tmp_sale Model name should be replaced by TmpSale name. Cakephp模型名称应为Singular, tmp_sale模型名称应替换为TmpSale名称。 The query of cakephp shown in below. Cakephp的查询如下所示。 You should try this 你应该试试这个

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

            )
        ));

Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM