Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6696189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:18:43+00:00 2026-05-26T06:18:43+00:00

I have a database table for users which contains common fields like password, email

  • 0

I have a database table for users which contains common fields like password, email etc. And there is also a field named level which defines user level such as member, editor or admin.

There is also some fields that specific for members, editors and admins which others don’t need. So I think I should create separated tables for user types.

And here’s the problem; how should I approach this problem if I want to follow Rails way? Both in terms of database design and associations.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:18:43+00:00Added an answer on May 26, 2026 at 6:18 am

    seems you are looking for a role-based authorization system, coupled with specific attributes for each role. One way to achieve this would be with a data model looking like this :

    .-------.1    *.------------.*     1.-------.
    | users |<-----| user_roles |------>| roles |
    '-------'      '------------'       '-------'
                         |
         .---------------+---------------------.
         |0..1           |0..1                 |0..1
     .--------.  .----------------------.  .----------.
     | points |  | some_other_attribute |  | room_ids |
     '--------'  '----------------------'  '----------'
    

    this way, you ensure that all attributes related to a specific role are deleted if that role is removed from the user (by cascade delete).

    You will have, though, to ensure that all your attributes models enforce validation rules like this :

    class Point < ActiveRecord:Base
        validates :relevant_association?
    
      def relevant_association?
        user_role.role.title == "Admin"
      end
    end
    

    if your user can only have one role, you can simplify this by adding a role field on the model, and then write validation rules on optional attributes (that belong_to a user) accordingly. Still,the former model offers more potential for future adjustments (creating a new role is just creating a new record).

    I’m not an expert on this matter though, so you can also continue to seek out inspiration ; the declarative_authorization gem provides an explanation of its data model that you may find interesting, too:

                         includes                   includes
                          .--.                        .---.
                          |  v                        |   v
    .------.  can_play  .------.  has_permission  .------------.  requires  .----------.
    | User |----------->| Role |----------------->| Permission |<-----------| Activity |
    '------' *        * '------' *              * '------------' 1        * '----------'
                                                        |
                                                .-------+------.
                                             1 /        | 1     \ *
                                   .-----------.   .---------.  .-----------.
                                   | Privilege |   | Context |  | Attribute |
                                   '-----------'   '---------'  '-----------'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MySQL database which contains a table of users. The primary key
I have a table, users, in an Oracle 9.2.0.6 database. Two of the fields
I have a table of Users (tblUsers) which contains details of University staff. I
I have a user table in my database which contains two columns FirstName and
Learning php! I have a sql database which contains a table called 'images' which
I have a database table which holds meta data about images, the field in
I have a table in a database that contains two fields id name I
I have a database table transaction which stores all the transaction made by users
I have a user table in my mysql database that has a password column.
An example for the sake of the question: I have a database which contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.