Answer the question
In order to leave comments, you need to log in
How to deal with the EAV architecture, where each value type has its own table?
I decided to use the EAV architecture for the online store, or rather for storing the characteristics of goods.
The simplest way to store all values in string formats. But this is long and not entirely correct. I read on the Internet that for each value type you need to create your own table, for example, stringAttrValue, intAttrValue, textAreaAttrValue.
Accordingly, we must have a table of type - id, attr_id, attr_type. The very problem is in the attr_type field, or rather, in what form to store the value type - either, as I read, int, textarea, string, or create another table with a list of value types and already take the id of the value type.
And after that, you have to write a lot of joins to get all the values from each table of the characteristic value type?
Answer the question
In order to leave comments, you need to log in
Instead of additional tables for each type, you can create additional columns.
entity_id # INT, ссылка на объект, которому принадлежит свойство
attribute_id # INT, ссылка на инфу о свойстве
value_int # INT, значение целочисленное
value_varchar # VARCHAR, короткий текст
value_text # TEXT, длинный текст
value_whatever # и так далее: DATETIME, ENUM, DECIMAL
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question