Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Database users and groups model

I have 2 entities: users and groups. Easiest model is user(id,name,etc...), group(id,name), user_group_rel(user_id,group_id). But I need to include groups into other groups. One user can be in many groups and groups can include users and subgroups with own users and subgroups! Need help with database model!

Users and groups

like image 999
VeroLom Avatar asked Dec 22 '22 17:12

VeroLom


1 Answers

While I agree with Ken Down's nomenclature, I don't necessarily agree that users and roles are the same entity.

Base Entities:

Users     (user_id, user name, real name, user_status, etc)
Role      (role_id, role name, role_password, etc)
Privilege (priv_id, base object, functionality, what have you)

Associative entities:

User has Role (0 - n) (user_id, role_id)
Role has Role (0 - n) (role_id, has_role_id)
User has Privilege (0 - n) (user_id, priv_id)
Role has Privilege (0 - n) (role_id, priv_id)
like image 143
Adam Musch Avatar answered Dec 27 '22 01:12

Adam Musch