Answer the question
In order to leave comments, you need to log in
How to make double link yii2?
Hello!
How can you build a double bond in yii2?
Created a CRUD model through the Gii of the Client table. With the help of hasOne, a relationship with the Subnet table was inferred.
How can I display in the gridview of the Client model the relationship with Bras.name?
Answer the question
In order to leave comments, you need to log in
client:
public function getSubnet(){
return $this->hasOne(Subnet::class, ['id' => 'subnet']);
}
public function getBras(){
return $this->hasOne(Bras::class, ['id' => 'bras'])->via('subnet');
// или
// return $this->hasOne(Bras::class, ['id' => 'bras'])->viaTable(Subnet::tableName(), ['id' => 'subnet']);
}
ClientSearch {
public $brasName; // добавляем атрибут в модель поиска
}
'id',
[
'attribute' => 'brasName', // выводим в гриде
'value' => function(Client $model){
return $model->bras ? $model->bras->name : null;
}
],
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question