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

enter image description here

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

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -