Different Types Of Groups With Different Associations. How to organize this?
I am writing a application in cakePHP, but this is more of a general database question. I am a novice in writing database applications and am new to cakePHP.
In my application there are users, and 2 distinct types of groups that they can have associations with. For instance.
Type A - Groups of type A include things like {new users, experienced users, advanced users, administrators, super users}. A user must belong to 1 and only 1 of these groups. These groups are mainly used to control what a user can do with the application.
Type B - Groups of type B include things like {friends, family, co-workers, small-mix, medium-mix, large-mix etc...} A user can belong to many of these groups or none at all. These groups are mainly used to control who we invite to certain functions and events.
At first I thought I would have a table called "Groups" and simply add a fiend called "type" so I can keep them distinct but reuse the same table. All fields would most likely be identical for the 2 different types of groups.
But, I don't think this will work, since a user can belong to only 1 of type A, but they can belong to any number of groups from type B. How could the relationship be different using only 1 table?
My only thought I have left is to create 2 tables, one for each group type. The fields would be repeats at least for now, but this would allow me to have different relationships to the user table, for example has one, has 0 or more...
Is there a better way to do this? Is m开发者_如何学编程y suggested solutions appropriate?
It appears to me that 2 separate tables is a correct solution, because you have 2 different concepts that you have called "group". Just rename the first "group" to something else such as "Category" and all will make sense.
精彩评论