I have two tables: people & categories
People
- id
- name
- ...
Categories
- id
- name
- description
And another table with the relation between both as one person can have multiple categories assigned:
PeopleCategoriesAssn
- peopleID
- categoryID
I can show the categories IDs in my gridview (views/people/index.php) with:
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
...,
[
'label' => 'Category',
'value' => function ($data) {
$output = '';
foreach($data->peopleCategoriesAssns as $request) {
$output .= $request->talentCategoryID.'<br>';
}
return $output;
},
],
...
which uses this from models/People.php
public function getPeopleCategoriesAssns()
{
return $this->hasMany(PeopleCategoriesAssn::className(), ['peopleID' => 'id']);
}
How could I show the categories names instead of the categoies IDs within the gridview and also, what should i do at /models/PeopleSearch.php in order to allow search/filter on that field?
Thank you in advance,