As in fields() model to deduce connections one-to-many?

There are 3 models (Building, Firm and Category)

Infer fields in the model Firm associated model Building this:
public function fields()
{
 return [
'id',
'name',
'phones',
'building',
];
 }


but how to display Category? The link generated by standard means gii,
all methods links
/**
 * @return \yii\db\ActiveQuery
*/
 public function getBuilding()
{
 return $this->hasOne(Building::className(), ['id' => 'building_id']);
}

/**
 * @return \yii\db\ActiveQuery
*/
 public function getFirmCategories()
{
 return $this->hasMany(FirmCategory::className(), ['firm_id' => 'id']);
}

/**
 * @return \yii\db\ActiveQuery
*/
 public function getCategories()
{
 return $this->hasMany(Category::className(), ['id' => 'category_id'])->viaTable('{{%firm_category}}', ['firm_id' => 'id']);
 }

June 14th 19 at 20:03
1 answer
June 14th 19 at 20:05
Solution
public function fields()
{
 return [
'id',
'name',
'phones',
'building',
'categories',
];
 }

Doesn't that work?
Yes, it works -- when did using extraFields gave an error,
why not proell :)

Thank you very much :)

shame... - Mohamed_Lind75 commented on June 14th 19 at 20:08
Yeah well... it happens. :) - Giles_Luettgen18 commented on June 14th 19 at 20:11
there's another question:

if we have a Firm and Building one-to-one,
in the model the Firm we're just in fields insert field 'building',
that is why in the model Building we can't insert the field 'firms' ?
throws out an error 500 - Mohamed_Lind75 commented on June 14th 19 at 20:14
the model Building is obtaining firms
/**
 * @return \yii\db\ActiveQuery
*/
 public function getFirms()
{
 return $this->hasMany(Firm::className(), ['building_id' => 'id']);
 }
- Mohamed_Lind75 commented on June 14th 19 at 20:17
And 500 how the text falls out though? I unfortunately can't right now to test. - Giles_Luettgen18 commented on June 14th 19 at 20:20
, falls server error, past the flying yii2 debugger error
59d4c381aebde381829580.png
if you change firms on the firm or other word, then yii2 vykidyvali exception (they say there is no such field)

in the logs of nginx 200 lines of errors generated, Fig parse - Mohamed_Lind75 commented on June 14th 19 at 20:23
Try in the beginning index.php to insert rows:
ini_set('error_reporting', E_ALL);
 ini_set('display_errors', 1);
 ini_set('display_startup_errors', 1);
- Giles_Luettgen18 commented on June 14th 19 at 20:26
And you have syntax errors the IDE does not show? - Giles_Luettgen18 commented on June 14th 19 at 20:29
all-made a log of the error:
spoiler

2017/10/04 19:06:29 [error] 12735#12735: *1 FastCGI sent in stderr: "PHP message: PHP Fatal error: Maximum function nesting level of '256' reached, aborting! in /home/m/PhpstormProjects/2gis/vendor/yiisoft/yii2/db/mysql/Schema.php on line 205
- Mohamed_Lind75 commented on June 14th 19 at 20:32
Ha. Looks like they have recursively each other dragging! Will wagethe Firm->Building and Building Firms. And each of these firms drags the building. which drags the firm, which pulls the building... and so 256 times :) - Giles_Luettgen18 commented on June 14th 19 at 20:35

Find more questions by tags Yii