Client:
public function getSubnet(){ return $this->hasOne(Subnet::class, ['id' => 'subnet']); } public function getBras(){ return $this->hasOne(Bras::class, ['id' => 'bras'])->via('subnet'); // or // return $this->hasOne(Bras::class, ['id' => 'bras'])->viaTable(Subnet::tableName(), ['id' => 'subnet']); }
ClientSearch:
ClientSearch { public $brasName; // add the attribute to the model search }
gridview:
'id', [ 'attribute' => 'brasName', // print the grid 'value' => function(Client $model){ return $model->bras ? $model->bras->name : null; } ],