Jichao Jichao - 1 year ago 182
MySQL Question

Yii2 how to translate cascade select in where clause to activequery?

Two tables

, I need to dump all the unanswered questions for specific user. In sql

select * from question where question.user_id = user_id
and (select count(*) from answer where answer.question_id = question.id) = 0

But how could I turn this command to activequery?

Question::find()->where(['user_id' => user_id]) ....

Answer Source

An active query to find each question for a given user with no answer.

Question::find()->leftJoin('answer', 'answer.question_id=question.id')
                ->where(['question.user_id' => $user_id])
                ->andWhere(['answer.id' => null)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download