Answer the question
In order to leave comments, you need to log in
What is the best way to set a structure for data of different types?
So, I have a User model with all the inherent devise's fields.
Each entry must also have a set of some additional fields, the set of which is strictly defined, but at the same time, this set can be changed at the will of the site administrator. Let's say this set is stored in a table named profile_fields.
The most obvious would be to add an additional label like profile_field_values, and everything would be fine, but this label will have a fixed data type for the value column, and I need to make a selection by different types. For example, we have a user vasya who has the following add. fields:
Answer the question
In order to leave comments, you need to log in
The most suitable option cannot be advised without knowing your data volumes and how you plan to use it.
If the search time is not critical, there are few data types, you need a simple and portable solution, then I would advise option 1 with serialization of various types into a string.
The postgrew json/jsonb option adds flexibility/performance, but in json the simple types are number, string, and boolean. There are no dates or other types. Indexes are supported for jsonb. This decision means a hard link to the PG.
There is another option similar to 1, but with the assignment of columns of different types and storage in each property of its type. Requests will look something like this
SELECT * FROM profile_field_values
WHERE
(property_field="дата рождения"
and value_type="date" and value_date > ?)
and
(property_field="размер ноги"
and value_type="integer" and value_integer < ?)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question