yii2使用leftjoin如何生成on……and查询语句

$sql = Wrong::find()->where([
            't.fdUserID' => 4,
            't.fdStatus' => 0
        ])->alias('t')->leftJoin(Exercise::tableName().' exercise','exercise.id=t.fdExerciseID',['exercise.fdStatus'=>1]);
print_r($sql->createCommand()->getRawSql());

打印的sql语句为

SELECT `t`.* FROM `tbWrong` `t` LEFT JOIN `tbExercise` `exercise` ON exercise.id=t.fdExerciseID WHERE (`t`.`fdUserID`=4) AND (`t`.`fdStatus`=0)

请问下exercise.fdStatus=1这个条件为啥没生成,还有如何生成期望的sql语句

SELECT `t`.* FROM `tbWrong` `t` LEFT JOIN `tbExercise` `exercise` ON (exercise.id=t.fdExerciseID AND exercise.fdStatus=1) WHERE (`t`.`fdUserID`=4) AND (`t`.`fdStatus`=0)
阅读 5.7k
1 个回答
Wrong::find()
    ->where([
        't.fdUserID' => 4,
        't.fdStatus' => 0
    ])
    ->alias('t')
    ->leftJoin(
        Exercise::tableName().' exercise',
        'exercise.id=t.fdExerciseID and exercise.fdStatus=1'
    );
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进