Yii2与gridview中的组合并不起作用

时间:2017-03-10 05:38:48

标签: join gridview group-by yii2 sum

以下是我的询问:

$query = AssignApplicant::find()
                ->select(['sum(total_pay) as sum','applicant.first_name','applicant.last_name'])
                ->joinWith(['position', 'applicant'])->orderBy(['job_positions.id' => SORT_DESC]);
 $query->groupBy(['applicant_id']);

我的网格视图

GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'kartik\grid\SerialColumn'],
            [
                'attribute' => 'applicant',
                'value' => 'applicant.first_name',
            ],
            'sum'
        ],
    ]);

此apply.first_name的打印为null。当我在db中运行原始查询时,它可以工作。当我删除下面的行时,它显示first_name但不显示总和

->select(['sum(total_pay) as sum','applicant.first_name','applicant.last_name'])

1 个答案:

答案 0 :(得分:1)

我通过改变这个来解决:

 ->select(['sum(total_pay) as sum','`assign_applicant`.*'])