Yii2 Left在查询构建器中加入

时间:2017-05-26 02:12:44

标签: yii2 yii2-advanced-app

我有两个表,greeter.tsinterface Person { firstName: string; lastName: string; } function greeter(person: Person) { return "Hello, " + person.firstName + " " + person.lastName; } var user = { firstName: "Jane", lastName: "User" }; console.log(greeter(user)); 。在report_details表中,我有一个与表name相关的id。 Yii2中正确的语法是什么来获取report_details表中的for和from?这是我到目前为止的询问......

name

1 个答案:

答案 0 :(得分:0)

您可以使用->leftJoin( )

  $query = new yii\db\Query;
            $query->select('report_details.reference_no, report_details.subject, 
                          report_details.doc_for, report_details.doc_from, 
                          report_details.doc_date, report_details.doc_name, 
                          report_details.drawer_id, report_details.user_id,
                          name.name_id, name.position, name.fname, name.mname, name.lname')
                ->from('report_details')
                ->leftJoin( 'name', 'report_details.doc_for = name.name_id')
                ->where(['report_details.reference_no' => $model->reference_no]);
  $results = $query->all();