A
A
Andrey2018-05-21 08:54:51
Yii
Andrey, 2018-05-21 08:54:51

How to display data linked through an intermediate table in a gridview?

5b025e2ce0899145300548.png
I display a list of users using gridview. But I would also like to add belonging to the role (each user has one role). It can be displayed through the item_name link, but I want to display a full-fledged record, description. How can this be implemented

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Kim, 2018-05-21
@DronTat

[
  'label' => 'Роль',
  'value' => function($model){
    return $model->authAssignment->authItem->description;
  }
]

Just make sure the link chain exists and add eager loading to UserSearch:
$query = User::find()->with([
  'authAssignment' => function($q){
    return $q->with('authItem');
  }
]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question