D
D
Dmitry2020-10-05 11:35:45
Yii
Dmitry, 2020-10-05 11:35:45

How to make connections and request in the controller correctly?

There are 3 tables "blud", "tproduct", "tproducts_attributes"
"blud" - stores a list of dishes
"tproduct" - stores a list of products
"tproducts_attributes" - a table for linking "blud" and "tproduct"

5f7ad6d8dede8499586896.jpeg

Please tell me how to make the links correctly in the many-to-many models (please check if I made the links correctly) and linked them in "tproducts_attributes" and how to correctly make a request in the controller to display only those lists of dishes that relate to the product (which are indicated in the "tproducts_attributes" table) ??

So far in the Controller I display like this (all dishes):
$values = Blud::find()->all();

Communication in the "blud" model:

public function getBluds()
    {
        return $this->hasMany(Blud::className(), ['blud_id' => 'id']);
    }


Communication in the "tproduct" model:
public function getBluds()
    {
        return $this->hasMany(Blud::className(), ['tproduct_id' => 'id']);
    }


Relationships in the "tproducts_attributes" model:
public function getBlud()
    {
        return $this->hasOne(Blud::className(), ['id' => 'blud_id']);
    }

    public function getTproduct()
    {
        return $this->hasOne(Tproduct::className(), ['id' => 'tproduct_id']);
    }


Rules in the "tproducts_attributes" model:
,

            ,

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