I'm struggling in database design problem and it seems I can't get it out properly.
I need some help on this. Maybe it's a dumb case but I'd like to validate or correct my scheme and then go ahead.
The app should behave like this:
- a user can be part of multiple accounts and have different roles (admin or not)
- an account can have one or many groups
- each group can have one or many members
- a member can be part of many groups
-
a member can be either an user or a legal entity (company)
-
if it's a company, then the company is represented by a user
- a user can represent 0,1 or many companies in different groups
Here is my actuel scheme where I have a n-to-m relationship on Groups-User-Companies.
Here in GroupMembers, the users_id or companies _id will be filled either it's a legal entity or individual.
And the CompanyRepresentedBy table will contain the group_id, user_id and company_id
I'm not really sure of this scheme.
To have a better understanding, here is a diagram of the relationship Account-Group-Member-User
Thank you all!
PS: I can provide the MySQL Workbench file if needed
Best Answer
Why would you split into User and Account?
What is Group standing for? It's relating to Account and Company now, that I'm thinking to GroupType or separated tables AccountGroup and CompanyGroup
Above all, based on your current requirements, following my suggestions:
https://dbdiagram.io/d/5d6f2704ced98361d6de2d0d
a user can be part of multiple accounts and have different roles (admin or not)
an account can have one or many groups
each group can have one or many members / a member can be part of many groups
a member can be either an user or a legal entity (company)
if it's a company, then the company is represented by a user / a user can represent 0,1 or many companies in different groups
Please noted that this is for an idea, not a fullfill solution. I hope this help you much.