Answer the question
In order to leave comments, you need to log in
Am I missing something in relations yii2?
Hello. There is a question regarding relations in yii2. I have three tables: products, files, files_thumb. Files is related to products and thumbs is related to files. I need to select certain products with full photos and thumbnails, while full photos are selected by a certain parameter, not all.
In the products model, I write the following relations:
public function getFile() {
return $this->hasMany(Files::className(), ['id_obj' => 'id']);
}
public function getThumbs(){
return $this->hasMany(FilesThumb::className(), ['id_file' => 'id'])->via('file');
}
$res = ShopProducts::find()->joinWith('thumbs')->where("files.onmain=1")->all();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question