可以混合where()子句

时间:2016-01-20 11:25:44

标签: yii2 yii2-advanced-app

我有以下代码(它缩短了,否则显示的时间太长了):

Feedback::find()
        ->where(['feedback.fg_id' => $this->id])
        ->orWhere(['feedback.fg_id' => $this->id, 'feedback.closed_time' => NULL, '<' => ['feedback.survey_end_date', new Expression('NOW()')]])
        ->all();

由于orWhere()

中的最后一个语句,此代码不起作用

我现在的问题是:我如何结合orWhere内的语法?这是因为我需要or块内的所有语句。

矛盾的sql代码应该是:

SELECT * FROM feedback WHERE
(feedback.fg_id = 1) OR (feedback.fg_id = 1 AND feedback.closed_time IS NULL AND feedback.survey_end_date < NOW())

1 个答案:

答案 0 :(得分:3)

是的,你可以把你的条件结合起来......

Feedback::find()
->where(['feedback.fg_id' => $this->id])
->orWhere(['AND',
    ['feedback.fg_id' => $this->id],
    ['feedback.closed_time' => NULL],
    ['<' , 'feedback.survey_end_date', new Expression('NOW()')]
 ]);