CakePHP找到多个'OR'的条件

时间:2013-11-29 17:18:30

标签: cakephp

我真的很头疼让这个工作正常。这是我在原始MySQL中的理想结果:

WHERE `EmailTemplate`.`is_archived` = '0' 
AND
((`EmailTemplate`.`project_id` IS NULL) OR (`EmailTemplate`.`project_id` = 101))
AND
((`EmailTemplate`.`user_id` IS NULL) OR (`EmailTemplate`.`user_id` = 44))

这如何转换为CakePHP条件数组?

1 个答案:

答案 0 :(得分:2)

最终解决了这个问题。

    $templateConditions = array(
            'EmailTemplate.is_archived' => 0,
            'AND' => array(
                       'OR' => array(
                                array('EmailTemplate.project_id IS NULL'),
                                array('EmailTemplate.project_id' => $this->request->data['Project']['project_id'])
                               )    
                     ),
                     array(
                       'OR' => array(
                                array('EmailTemplate.user_id IS NULL'),
                                array('EmailTemplate.user_id' => $this->Auth->user('id'))
                               )
                     )
            );