SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
Thread: User class and subclasses
-
Oct 4, 2007, 21:59 #1
- Join Date
- Oct 2007
- Posts
- 2
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
User class and subclasses
My question is part Rails and part database design pattern:
I've got several classes of users in my system:
Resident
Sponsor
Facility
Administrator
My thought is to have a base User class for authentication purposes, and instantiate one of the user classes (subclasses of User?) based on the class of the user.
1) is this a smart design pattern for the database? A 'users' table with authentication information and a 'user_class_id' field that points to a 'user_classes' table, from which the proper subclass is instantiated?
if not, what would be the best way to design this?
2) how would you model this in Ruby on Rails? particularly if the user class is in the User table?
Thanks much!
-Colin
-
Oct 8, 2007, 23:21 #2
- Join Date
- Oct 2007
- Posts
- 2
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Wow, 4 days without so much as a peep. I was starting to think I was misstating my question, but I found the beginnings of an answer HERE:
http://www.railsforum.com/viewtopic.php?pid=40434
-
Oct 9, 2007, 05:38 #3
- Join Date
- Aug 2005
- Posts
- 986
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
You could use one table for the login information (users), and other tables for the Residents, Sponsors, etc. Now you make a many-to-many relation between residents and users, sponsors and users, etc. This way you can have multiple users for one sponsor. Only if you need this flexibility.
Bookmarks