Answer the question
In order to leave comments, you need to log in
How to store a dynamic number of properties?
There is a product, it can have a different number of properties, and when ordering, the client himself specifies the parameters of these properties (for example: color: black, number of legs: 3, folding: yes, pattern: stripe, etc...) How to store it all? Well, let's say the product is understandable: id_товара
, название_свойства
. And how to store what users enter?
Answer the question
In order to leave comments, you need to log in
OneToMany - 2 tables.
linked by onetomany link:good.id = good_property.good_id
A stupid, but effective option
to store all parameters in one field of the database as a serialized array
For each property, you need to determine its type and, accordingly, bind the write-read algorithm, interface, and storage system, depending on the type. This problem is generally related to working with metadata and metaalgorithms.
Create tables:
1. Property name (id, name, goodid - product)
Example: 222, "Color", 333
2. Possible values (id, propid, value)
Example: 1, 222, Black
2, 222, White
And then that
3. Users will enter: (id, userid, propvalueid, goodid - this field is already redundant)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question