为正在构造的查询设置查询参数的集合

时间:2019-01-22 23:27:04

标签: doctrine-orm doctrine query-builder laravel-query-builder

我正在尝试使用选项数组来构建查询,如您所见,这是我的数组选项:

    $sort = $this->getParam('sort', 'creation_date');
    $order = $this->getParam('order', 'desc');   
     $options = [
            'sort' => [$sort => $order],
            'filters' => [
                [
                    'field' => 'state',
                    'operator' => 'LIKE',
                    'bind_name' => 'state1',
                    'value' => 'read',
                    'type' => 'OR'
                ],
                [
                    'field' => 'state',
                    'operator' => 'LIKE',
                    'bind_name' => 'state2',
                    'value' =>  'green'
                ]
            ]
        ];

结果我有这个查询:

SELECT COUNT(*) FROM `mytabel` `mytabel` INNER JOIN state_type t ON t.id_state_type = `mytabel`.id_state_type WHERE (`mytabel`.`state` LIKE :state1) **AND** (`mytabel`.`state` LIKE :state2) ORDER BY `mytabel`.`creation_date` desc

Params
state1  %read%
state2  %green%

我的问题是我如何在查询中使用OR而不是AND(数组选项)?因为结果是我想同时拥有这两个属性(state1%read%,state2%green%)。

谢谢

0 个答案:

没有答案