views:

60

answers:

1

Hi,

This question would be a bit childish, I have three tables, users, usergroups and contacts. In my system, the end user can create a contact and subsequently he\she may define the visibility of the contact by setting only for that user, or for a set of users or a set of usergroups. So I am wondering, how my database design would be, it should be many to many between users and contacts or many to many between usergroups and contacts. Definitely there is a one to many relationship between users and usergroups.

Thanks Thurein

+1  A: 

If you have the possibility to set the visibility for a set of users or a set of usergroups then you need both m2m tables you mentioned. One contacts_users and one contacts_usergroups.

What I've said is true if "set of users" is different from a single "usergroup".

dierre
Yeah, how about this, there is a one to many relation between users and usergroups, and, I am only required to set the visibility to a set of usergroups.
Thurein
Then you're fine with a single m2m table. You need the other one only if you want to set the visibility to a single user.
dierre
Wait a moment: one2many users-usergroups? Are you sure? Shouldn't it be m2m? Users have many Usergroups and Usergroups has many Users?
dierre
Yes, correct, m2m between users-usergroups. So, you also think, it is correct to have m2m relationship between usergroups and contacts, if I am dealing the visibility only with the use group? So, the design would be m2m between contacts and usergroups, and another m2m between users and usergroups, right? :)
Thurein
Yes, I think so if I understood correctly your problem. I mean to understand a relationship is pretty simple. Does the user hide the contact from many UserGroups and can't UserGroup see many contacts? If yes then it's a m2m. Yeah, I'm pretty sure you can accept my answer :)
dierre