On Mar 7, 2010, at 4:38 PM, mydoghasworms wrote:
Sorry if this is covered somewhere, but I am unable to find something
on it:
Does Hobo support multiple user models? E.g. I have needs for
different types of users. I'm not sure whether any of the other
solutions, STI or Polymorphic relationships are the answer. In my
case, I need to provide users that place adverts for jobs
(advertisers) and users who are job seekers. They would have widely
varying attributes, and I would see them as completely different
entities, so I would think having separate models would be best.
However, how does Hobo engage with multiple user models? How does this
affect authentication and permissions?
It's possible to have multiple independent user classes - it gets a
little hairy, as you end up needing more than one controller to handle
login. But the session code doesn't really notice - it stores a typed
id (example: "user:123") for current_user, so it works fine.
I've used STI successfully on a couple projects - it avoids some of
the duplication. A couple notes:
- don't call hobo_user_model in the subclasses. It's bad. :)
- you'll need to declare the lifecycle in each user model; this is a
known issue with the current lifecycle implementation.
- the fields block doesn't need to be repeated in each model
- if you've got a singly-rooted user class hierarchy (in other words,
some base User class in common), you won't need :polymorphic on
associations to users. That's only needed when the record can't be
retrieved by ID from a single table - STI is smart enough to return
the correct type, even when doing a find on the base class.
- you *can*, however, specialize user associations to get some type-
checking behavior. In other words, declaring
'belongs_to :advertiser' (where Advertiser < User) will only allow
Advertisers to be assigned.
You also might want to split most of the more detailed info off from
the users table - advertisers have a nasty habit of eventually wanting
multiple user accounts to access the same profile, etc.
If you run into any problems, please get in touch - STI support is
solid, but that doesn't mean you won't find a corner that I missed
that's broken.
--Matt Jones
--
You received this message because you are subscribed to the Google Groups "Hobo
Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/hobousers?hl=en.