Answer the question
In order to leave comments, you need to log in
How to make a connection between three tables in the database (products, categories and additional fields)?
In general, there is a simple site on Yii 1.1, it has a product catalog. Products are divided into categories (many-to-one relationship). It is necessary to make it possible to add (and, of course, display in the view of a specific product) additional fields to each category (for example, if this is the category "Wallpaper" - you can add the fields "color", "texture", "footage", etc. .d.), but at the same time, obviously, it is necessary that their values are filled in for each product separately.
DB Diagram:
Relationships in Yii Models:
Item Model:
return array(
'category' => array(self::BELONGS_TO, 'ItemCategory', 'category_id'),
'fields' => array(self::MANY_MANY, 'ItemField', 'items_fields_values(item_id, field_id)'),
);
return array(
'itemCategory' => array(self::BELONGS_TO, 'ItemCategory', 'item_category_id'),
'items' => array(self::MANY_MANY, 'Item', 'items_fields_values(field_id, item_id)'),
);
return array(
'items' => array(self::HAS_MANY, 'Item', 'category_id'),
'itemsFields' => array(self::HAS_MANY, 'ItemField', 'item_category_id'),
);
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