$TourismBarrage = CenterSharing::find()->select('user_id,nickname')
->with('user')
->groupBy('nickname')
->asArray()
->all();
在CenterSharing的模型中:
public function getUser()
{
return $this->hasOne(UserWechat::className(),['unionid'=>'user_id'])
->select('unionid,avatar');
}
with连表注意:
1. 若这样写
public function getUserWechat()
{
return $this->hasOne(UserWechat::className(),['unionid'=>'user_id'])
->select('unionid,avatar');
}
报错: 类名重复 (粉红色标注)
2. select('unionid') (绿色标注)
这个必须写,因为你 用到了 ['unionid' => 'user_id'], 不写的话,照样报错