D
D
dkrylov2017-04-16 16:14:55
MySQL
dkrylov, 2017-04-16 16:14:55

How to make a hasMany link with a photo of goods for an online store?

Hello dear programmers! =)
Situation (a little exaggeration for simplicity):
There is a table product, there is a model Product [id, name]
There is a table product_photos [id, product_id, url]
How can I make a hasMany relationship for the product table with the product_photos table? Do I need to create an ActiveRecord model for the product_photos table?
Perhaps the question will seem strange, so I will explain why I ask this way. To link categories with products, the following construction is used, which is written in the Catalog model:

public function getProduct()
{
        return $this->hasMany(Product::className(), ['catalog_id' => 'id']);
}

And I have a question that I asked above. Do I need to create a model for a table with a photo, or is it done in a more competent way?)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Fortop, 2017-04-16
@dkrylov

What alternatives do you have?
The fact is that AR itself is a sad pattern.
But in general - yes, you need a model for a separate entity in the database
Exclusion of a table of many-to-many relationships that are not entities.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question