Answer the question
In order to leave comments, you need to log in
How to organize a database schema?
Good afternoon, there is the following database schema:
i.e. the user is a member of a group, and the group has a list of menus displayed in the interface. In this case, we can get the menu list from a specific user. But sometimes you need to add a separate menu to the user, regardless of the group. What is the best way to store it in the database?
Answer the question
In order to leave comments, you need to log in
it is better to store such special cases separately, for example user_custom_menu, and store user and menu there, and then join the result to the main query through union all. In principle, the same as Roman Kitaev proposed in the second version.
Option without changing the scheme: add the user to the group, where there will be only one, hang the necessary menus.
Option with the scheme: M2M on the menu and user (same as user_group and group_menu)
Add the id_user field to the group_menu table. When the menu is assigned via a group, it will be null, if via a user - id_group=null. And yes, the name of the table will no longer match the content - you can rename it. The query returning the menu will need to be rewritten accordingly.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question