CakePHP 3.x或处于具有多个相同字段的查找条件中

时间:2018-12-17 11:39:02

标签: cakephp cakephp-3.0 cakephp-3.x cakephp-3.6

我想查询数据库

Plates.page_number => 1 OR Plates.page_number => Cover

我正在尝试使用以下代码,但是由于数组键重复,我没有得到想要的结果,如何在同一字段中搜索两个不同的值?

   $query = $this->Ledgers->find('all', array(
        'contain' => array(
            'Plates' => [
                'conditions' => [
                    'OR' => [
                        'Plates.plate_title' => 'Front Cover',
                        'Plates.page_number' => '1',
                        'Plates.page_number' => 'Cover' // Duplicate Array Key
                    ]
                ]
            ], 'Plates.PlateImages', 'Tribes'
        ),
        'conditions' => array(
            'Ledgers.disabled' => 'n', 'Ledgers.id IN' => $ledgerIds
        )
    ))->orderAsc('ledger_title');

1 个答案:

答案 0 :(得分:1)

请尝试将条件包装在单独的数组中,例如:

'OR' => [
    ['Plates.page_number' => '1'],
    ['Plates.page_number' => 'cover'],
    ...
]

更多信息可以在CakePHP文档中找到:

Query Builder -> Advanced Conditions