rails && users && roles
Reply to all Reply to allForward Forward Print Add Chris to Contacts
list Delete this message Show original Message text garbled?
11:58 am (3½ hours ago)
Okay, I've been thing about this whole user/role business with Rails.
A restaurateur has multiple restaurants
A restaurant has multiple restauranteurs
A restaurant has multiple chefs
Both restaurateurs and chefs can be any other kind of user as well, i.e.
The base data for all users is the same:
create table user
create table restaurateur
Rails STI won't work because a user is not limited to a single
So, has_many :through seems the way to go. However, I want concrete
models for each user type, i.e. Restaurateur, Member, Chef, etc.
has_many :restaurants, :through => :restaurateurs
has_many :users, :through => :restaurateurs
With this setup, if I wanted to iterate through each restaurateur and
print out the email address, I would have to do something like
I want to clean the api up so that I can just do restaurateur.email.
My thought was to create a UserProxy module:
and then include the proxy in each user based class, i.e.
This cleans up the api significantly and allows the proxy to be used
between all user types.
Of course, if the user class changes, so does the proxy, which is a big
pain in the ass for maintenance.
Well, if the user class changes, updating the proxy is the least of
your concerns. You'll also have to update the associations in every
class, change the db column names or add the :class_name option to all
your associations, and so on. So I'm not sure that's a good strike
against your current solution.
I haven't really thought it through in detail, but have you considered
a "Role" model and join table. A user has many roles (owner, chef,
marketer, etc.). You can hook up the associations with using the
foreign_key and conditions options, _and_ it gives you some flexibility
to add more roles in the future without necessarily adding more tables