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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:26:33+00:00 2026-05-16T14:26:33+00:00

Single Table Inheritance using ActiveRecord. Since we can use @test = Employee.all and find

  • 0

Single Table Inheritance using ActiveRecord. Since we can use @test = Employee.all and find all the employees created. How does rails do this? Since we only use a User Table. How does it know about employees and retrieve only employees? Rails Magic? Explanation anyone? Thank you in advance.

Base Class : Person (inherits ActiveRecord)
Sub-Class: Employee, Supervisor, Manager (each inherit Person)

So my Person table needs to have a _type and _id field to make the table polymorphic.

My next question is how do I get Employee Associated to the Person table and when you save an employee, how do you get it to actually put in Employee in the person_type 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-16T14:26:34+00:00Added an answer on May 16, 2026 at 2:26 pm

    To indicate to Ruby on Rails that the
    users table needs to support Single
    Table Inheritance you need to add a
    column named ‘type’ to the users
    table. Here is my users table
    definition:

    CREATE TABLE users ( id INT NOT
    NULL AUTO_INCREMENT, user
    VARCHAR(15) NOT NULL UNIQUE, pass
    VARCHAR(40) NOT NULL, type
    VARCHAR(20) NOT NULL, PRIMARY KEY (id) );

    In the column named type you
    should store the name of the class,
    the class type, that should be used
    for each user. To mark an certain user
    as an admin set his type to
    ‘Administrator’. By setting a user’s
    type to ‘Administrator’ you are giving
    him full administrator privileges as
    defined in your Administrator model
    class.

    http://juixe.com/techknow/index.php/2006/06/03/rails-single-table-inheritance/

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

Sidebar

Ask A Question

Stats

  • Questions 509k
  • Answers 509k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer There isn't an implicit cast of Int to String in… May 16, 2026 at 4:32 pm
  • Editorial Team
    Editorial Team added an answer Why have the states interact directly with the filestream? Single… May 16, 2026 at 4:32 pm
  • Editorial Team
    Editorial Team added an answer I'm not aware of any property that you could use… May 16, 2026 at 4:32 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm currently using ActiveRecord single table inheritance. How can I cast one of my
I am using single table inheritance in my rails application, and want to explicitly
I am using Single Table Inheritance for managing different types of projects. Models: class
I am using Single Table Inheritance for managing different types of projects. I decided
I'm using single table inheritance for my application. My polymorphic type is Maintenance with
Is it possible to use generic support with single table inheritance, and still be
I have few DB tables, witch are build using inheritance from one table witch
I'm building a multilingual website. I've been thinking about using a single table for
I would like a little confirmation that I'm doing this correctly. Using rails single
I have the following 3 rails classes, which are all stored in one table,

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.