V
V
Valentine2016-04-12 20:04:22
Java
Valentine, 2016-04-12 20:04:22

How to solve the problem with this database architecture?

Good day everyone! I would like to consult on the database architecture ( Mysql ), or rather on the part that is responsible for my categories, products, etc. I have no experience in development, except for the project that I do for the portfolio. Services and DAO layers are already written on almost all of these objects.
The point is that I am creating a "universal store", and I was trying to create such an architecture, under which it would be convenient and fast for me to receive any data, i.e. I assumed a top-down search by ID, because by int value search is faster. But no matter how I tried, I could not get around one problem: the database structure is such that, let's say, "Cars" will have many characteristics, among them: Power, Number of cylinders, Class, etc. But also at, there will be the same parameters, it is clear that not all. Therefore, in the table characteristic_name there will be many identical fields for each subject, i.e. a hundred capacities, etc. I would like them to refer to the same power, but I am already implementing the work of the database so that when editing a record, if there are links to it, a new one is simply created. This, however, is not relevant to the case. I also put the manufacturer in the characteristics, although a separate table can be made for it. I hope for your experience, help and sound criticism. Again, I have no experience with this.
Below are two diagrams, one and the same, just in the example I drew, there are filled fields to make it easier to imagine everything.
Ps View is for the front-end so that he understands how to present information to him.
Pps Subject is an absurd name, I know it myself, but so far I can’t think of a better one)
811cf7be54474de7b0dd0fd2c45566d2.jpgf4bf1f8b4a4047c08ce028a1bf6be1b2.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
nirvimel, 2016-04-12
@Waynes

  1. If it characteristic_valueis bound to subject_model, characteristic_name(why not just name this table characteristics, because something else besides the name can be stored there) you can not bind to subject. This achieves the independence of characteristics from the subject and the absence of duplicates among the characteristics.
    PS: I wonder in what sense a drill (tool) can be a subject .

E
Eugene, 2016-04-13
@zolt85

There is such a model, called the EAV model . In short, it separates the entity - attribute - value, i.e. the list of entities and the list of attributes are independent. This allows you to make "reusable" attributes if you like. That's the advantage of this model. Of the minuses, I can note the complexity of database queries to select specific data, and the speed of executing these queries is slightly lower. And so it is quite a viable model. Magento , for example, uses it in their e-commerce products.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question