yii2 - Two fields in a table related to a field in another table -
i have model/table solicitation 2 fields (user_id , analyst_id) related field id in model table user.
in view, have gridview fields:
[ 'attribute' => 'user_id', 'enablesorting' => true, 'value' => function ($model) { return $model->user->username; }, ] how same analyst_id (i need show username based id) ?
update

simply create relation analyst:
add in model:
public function getanalyst() { return $this->hasone(user::classname(), ['id' => 'analyst_id']); } displaying in gridview:
[ 'attribute' => 'analyst_id', 'enablesorting' => true, 'value' => function ($model) { return $model->analyst->username; }, ], or if analyst might not exist replace return part:
return $model->analyst ? $model->analyst->username : null;
Comments
Post a Comment