actually here's the code

$titleCat=FrontendSetup::findOne(['key_setup'=>'recomented']); $recomented=Category::find()->where(['name'=>$titleCat->value])->with('goods','goods.images','goods.prise','goods.addfeilds','goods.ratingCountAggregation','goods.ratingSumAggregation')->all(); if(isset($recomented)) { foreach ($recomented as $rec){ var_dump($rec->goods); } } 

gives this error

common \ models \ Category has no relation named "images". Sed Caused by: Unknown Method - yii \ base \ UnknownMethodException Calling unknown method: common \ models \ Category :: getimages ()

in /var/www/magaz.lc/vendor/yiisoft/yii2/base/Component.php at line 285

What error do not tell me?

  • It would seem so much easier, everything is written, just read. Our people need to poke their noses like a kitten) - Makarenko_I_V
  • @Makarenko_I_V poke isn't this site created for this? - Sergalas
  • A lot of questions about. Your can be interpreted as translate into Russian. And this is not the subject of SO. @ zhukov-roman already poked. - Makarenko_I_V
  • @Makarenko_I_V you apparently did not notice that I also poked him into the documentation. - Sergalas

1 answer 1

It's written:

 common\models\Category has no relation named "images" 

What does it mean:

 common\models\Category не имеет связи с именем "images" 

You need to create an AR link, like this:

 class Category extends ActiveRecord { // ... public function getImages() { return $this->hasMany(Image::className(), ['category_id' => 'id']); } } 

Read more in the official documentation.

  • The following documentation is written officially in the documentation. You can greedily load deeper nested links, such as abcd. All parent links will be eagerly loaded. So when you call the [[yii \ db \ ActiveQuery :: with () | with ()]] method with With the abcd parameter, do you greedily load a, ab, abc, and abcd links? What is the difference between this goods.images and ab? - Sergalas
  • @Sergalas You have no getImages () method. Read carefully and do not haytite links to off. documentation - Makarenko_I_V
  • @Makarenko_I_V please answer if I make a greedy nested download, why should I do a method getImages () in the Category there is it in Gods and find me the differences please with this code $customers = Customer::find()->with('orders.items')->all(); // доступ к деталям первого заказа первого покупателя // SQL-запрос не выполняется $items = $customers[0]->orders[0]->items; $customers = Customer::find()->with('orders.items')->all(); // доступ к деталям первого заказа первого покупателя // SQL-запрос не выполняется $items = $customers[0]->orders[0]->items; and this - Sergalas
  • @Makarenko_I_V and this $recomented=Category::find()->where(['name'=>$titleCat->value])->with('goods','goods.images','goods.prise','goods.addfeilds','goods.ratingCountAggregation','goods.ratingSumAggregation')->all(); if(isset($recomented)) { foreach ($recomented as $rec){ var_dump($rec->goods); } } $recomented=Category::find()->where(['name'=>$titleCat->value])->with('goods','goods.images','goods.prise','goods.addfeilds','goods.ratingCountAggregation','goods.ratingSumAggregation')->all(); if(isset($recomented)) { foreach ($recomented as $rec){ var_dump($rec->goods); } } $recomented=Category::find()->where(['name'=>$titleCat->value])->with('goods','goods.images','goods.prise','goods.addfeilds','goods.ratingCountAggregation','goods.ratingSumAggregation')->all(); if(isset($recomented)) { foreach ($recomented as $rec){ var_dump($rec->goods); } } except for the fact that there the array is called by the key and my foreach is Sergalas
  • Well, let's start with the fact that you do not have this section of code that produces this error. - Zhukov Roman