How to handle groups of users and single users in data models
I'm working on a CRM system that will have both individual users as well as "teams of users". I'm encountering a problem in assigning tasks as I would like开发者_如何学Python to be able to assign tasks/events/leads to individual users as well as to whole teams.
My problem is that traditionally my database table for tasks, leads, or events would tie that particular event to a user using a "uid" column. However, I'm not sure the best way to handle this (or how other systems handle this) type of thing.
I was thinking of adding a second column "is_team" that would be just be a bool. If the is_team column was set to true than the uid would be regarded as a team id for that particular row.
Any comments, suggestions?
What about nesting the Users, so you have a parent_id. In this parent_id a user can belong to a "virtual user" which is in fact a group. That way, one can assign an entity to a User or a Team.
Couple of thoughts.
First, you could remove the uid column from the tasks, leads, and events table and replace with a lookup table. You could either have two lookup tables, one for users and one for teams, or a single table that has columns for both users and teams.
Second, maybe re-examine your requirements. Do you really need the ability to assign to either a individual user or a team? In the instance of assigning to a single user, could you make them a team of one so that all things (tasks, leads, events, etc) are only associated with a team (even if that team only has one member)?
No matter what you choose, just try to keep it simple and be open to refactoring when/if you figure out a better way to represent your data.
精彩评论