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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:53:54+00:00 2026-05-31T22:53:54+00:00

If role is an STI table: class Role< ActiveRecord::Base self.inheritance_column= :role_type end And Student

  • 0

If role is an STI table:

class Role< ActiveRecord::Base
   self.inheritance_column= :role_type 
end

And Student & Counselor inherit Role:

class Student< Role
end

class Counselor< Role
end

And StudentDetail keeps extra information about one student:

class StudentDetail< ActiveRecord::Base
    belongs_to :student
end

And a user can be both student and counselor:

class User< ActiveRecord::Base
    has_many :roles
    has_one :student
    has_one :counselor
end

And number is a column in StudentDetail,
And role_id is a column in StudentDetail

Is it possible to get the following syntax to work?

User.first.student.number

Meaning: “if Role table has one student with user_id == User.first.id then User.first.student is not null and if StudentDetail has role_id== Student.where(“user_id= ?”, User.first.id).first.id, make “student” act as a StudentDetail record and get the number field.”

  • 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-31T22:53:56+00:00Added an answer on May 31, 2026 at 10:53 pm

    You will have the indirection User.first.student.student_detail.number out of the box. I don’t think this hurts much 🙂

    I see two options (at least) how to go further:

    • Define methods for the StudentDetail methods in Student:

      def number
        self.student_detail ? self.student_detail.number : nil
      end
      
    • Use method missing to do that automatically:

      def method_missing(name, *args, &block)
        self.student_detail ? self.student_detail.send(name, *args, &block) : nil
      end
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

def role?(role) return !!self.roles.find_by_name(role.to_s.camelize) end Can you help me understand what's happening in the
What is the role of activator class in eclipse plugin ?
I just created one role table and i defined role_id tinyint(1), even though i
Azure web role (MVC 3 project) wont' start with Twilio controller class I have
I have 2 entities Role & Translation. Role -> Role_ID, Code Translation -> Code,
I'm trying to build a modified role system that has the following class/relationship structure:
I have two classes: Role and CustomRole public class CustomRole { public string RoleName
I'm playing with this Azure web role sample . It contains a class derived
I have userid and role id fields in the table. In that table couple
What role should I give a sql login if I need the login to

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.