views:

116

answers:

2

How is the Community member/account of StackOverflow 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.

+2  A: 

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.

TJB
I'm wanting this to be done automatically.
Daniel A. White
@Daniel A. White : Is putting it in your code not automatic enough? Wherever you have the code to add the user to your system (e.g. add user entry to database) just add the code which puts them in that group. Any way you slice it, that code will have to go somewhere might as well simplify it and put it in whatever place seems most logical.
TJB
+1  A: 

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.

iddqd