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 7632127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:32:27+00:00 2026-05-31T06:32:27+00:00

I setup roles for the User model, for now, I just have a role

  • 0

I setup roles for the User model, for now, I just have a role string column for the users table. The value could be admin, salesperson, instructor or student.

Now I have a ScheduledSession model that an Instructor is supposed to teach. I have an instructor_id column, which is supposed to have an id from the users table (an user with a role of instructor).

So how can I setup the association in the models? in the User model is doesn’t seem right to add has_many :scheduled_sessions because if the role is a salesperson or an admin, it just doesn’t feel right. or setup something like belongs_to :user, :as instructor in the ScheduledSession model, but I get error Unknown key :as.

How would you set this up?

  • 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-31T06:32:29+00:00Added an answer on May 31, 2026 at 6:32 am

    You want to set up your belongs_to slightly differently in the ScheduledSession model.

    belongs_to :instructor, :class_name => 'User, :foreign_key => 'user_id'
    

    This allows you to refer to the instructor of a ScheduledSession object and have it point to an entity in the User table.

    There’s no way around having a has_many relationship on your User model if you want to pursue a role based User with each user having a single role. Without it, you’ll have no mechanism to retrieve the scheduled_sessions associated with a user.

    An alternative might be to use Single Table inheritance here, which would allow you to create Admin users who don’t have SchededSessions, but Instructors who do. You’ll still store all of these in the same table, but ActiveRecord will make it easier for you to compartmentalize them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a standard user/role setup which returns the current user's roles in a
I have a common User / Role setup, with a user_role join table. I'm
I have a User and an Admin role in my project. I created my
I have two models Users and Roles . I have setup a many to
So I have the basics setup already. This is my User model: # ==
I have a users model with Devise, and I've set up roles so users
I am slightly confused on how to setup my table. I have three roles
A User can have many roles, but only one role per Brand. Class User
Here is my current setup: Database Role - MyDbRole Schema - MySchema User -
EF 4.1 Database First approach. Say I have this table schema Users 1---M UserRoles

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.