Answer the question
In order to leave comments, you need to log in
How to store category IDs in the database?
Drastete, tell me in what form to store the category id in the database in the record.
Keep them in one field via varchar each id separated by a comma, or create multiple int fields to hold id there?
How to make it convenient to make a filter by categories later, where there will be a multi select with categories
Answer the question
In order to leave comments, you need to log in
Standard - in a separate table of many-to-many relationships.
The modern way is in a column with JSON type.
Govnokod - in a line separated by a comma or another separator.
For normal developers, not hipsters, we explain:
"In a column with the JSON type" - this is not a modern hype method, but a very rare option that should be used anywhere as Comrade advises. Rsa97 , but with great care and only in the cases intended for this: namely, when the structure of the stored data is not defined.
In this case, you must use the standard method with a linked table. Since when using standard storage methods, you can use all the features that the database provides, such as data integrity control, storage compactness, use in indexes, and so on. Not to mention the ease of querying and support from existing libraries.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question