O
O
Oleg Lysenko2016-07-29 23:49:15
Yii
Oleg Lysenko, 2016-07-29 23:49:15

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');
    }

The selection condition is such that files.onmain = 1;
I make a request:
$res = ShopProducts::find()->joinWith('thumbs')->where("files.onmain=1")->all();

The query itself is built correctly, but explain to me why, when I print $res, I see all the files, including those that do not fall under files.onmain=1, and when I print $res->thumbs, I see only that need.
Please explain what is happening here, what does he really choose? Thanks in advance for your replies.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question