我有以下代码(它缩短了,否则显示的时间太长了):
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())
答案 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()')]
]);