SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question 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

  2. #2
    SitePoint Member
    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

  3. #3
    SitePoint Guru
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •