How to make a double bond yii2?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
24 views
Hello!
How to build a double bond in yii2?
Created CRUD with Gii model of the table Client. With the help of hasOne has been bred relationship with table Subnet.
How to display in gridview model Client relationship with Bras.name?
5aebc71f0a091497238533.png
by | 24 views

2 Answers

0 like 0 dislike
Good morning.
You can create a link in the model Subnet communication on Bras and use the chain of these relations.
In the model Subnet
public function getBras(){ return $this->hasOne(Bras::class, ['id' => 'bras']); }

In GridView
'value' => 'subnet.bras.name'
by
0 like 0 dislike
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; } ],
by

Related questions

0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
asked Apr 9, 2019 by MityaevMaxim
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
110,608 questions
257,187 answers
0 comments
40,796 users