How would I implement a "Community" account-like data structure?
How is the Community member/account of Stack开发者_Go百科 Overflow work in terms of the ID being -1? Is it in the database? If not, how is it represented in code - is it a special instance of an account?
I am not looking for delving out privileges.
I want to replicate this so that my application has special "groups" that are defined in code and not in the database. How can this be done?
An example of what I want:
I have groups of users. In each group there is at least one user. However, I want to have an "all users group" that automatically has all the users.
If you want to have a 'global' group, you should just create one and automatically add each user to it when they are created. That way you don't need to treat it differently.
For the 'community user' concept, another generic mechanism would be a role. You could have a set of roles defined for your users, and there could be one role that corresponds to the 'community' user.
Role Based Authorization may be a good place to start looking.
I don't know how SO does it, but I would simply add a column to the user table like "user_type_id"
In another table, user_types, I would have a corresponding user type for that ID. For instance, "Community"
You can handle everything else based on if the user type is the community one. You would also have normal user types in that table for everything else.
It's probably a lot more simple than you're imagining it.
精彩评论