Tuesday, January 18, 2011

[Rails] Multiple roles of a user with STI

Folks,

I have setup Single Table Inheritance with my User model. Now the user
can have multiple roles. In my situation (a school app) the user can
be a Teacher (through which I want to access the students, grades etc)
and the same user can also be a Parent (through which I want to access
the children info). In STI, the type column in the user table can
store only one type i.e. either Parent or Teacher. So when this user
logs in and I want to access students at one time and children at
another - through Teacher or Parent models respectively.

The model hierarchy is as below -

class User < ActiveRecord::Base
end

class Parent < User
# relationships and functionality to work on children
end

class Teacher < User
# relationships and functionality to work on students and grades etc
end

Searched around but can't find anything on this. It doesn't look like
I can accomplish this through STI. However I have the Parent and
Teacher functionality setup through these STI models. What is the best
way to model/enable this?

Thanks for any pointers.

-S

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate