@
@
@chistya2016-09-22 17:19:26
SQL
@chistya, 2016-09-22 17:19:26

How to organize a database schema?

Good afternoon, there is the following database schema: cb64c07b25ac47bbab3631bca595e124.png
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

3 answer(s)
E
Edward, 2016-09-22
_

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.

R
Roman Kitaev, 2016-09-22
@deliro

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)

R
res2001, 2016-09-22
@res2001

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 question

Ask a Question

731 491 924 answers to any question