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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:12:55+00:00 2026-06-14T22:12:55+00:00

I was hoping I could inherit off an activerecord model, and use the subclass

  • 0

I was hoping I could inherit off an activerecord model, and use the subclass as I could the parent class. This does not appear to be the case, the AR relationships do not appear to work for the subclass.

class Manager < User
  belongs_to :shop
end

class Shop < ActiveRecord::Base
  has_many :managers
end

class PremiumShop < Shop
end

and

@premium_shop = manager.shop # Finds the shop.
@premium_shop = manager.premium_shop # Does not find the shop, NilClass:Class error

Is it possible to make this work?

  • 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-06-14T22:12:56+00:00Added an answer on June 14, 2026 at 10:12 pm

    The shop method exists for some instance of the Manager class because of the association you defined through the belongs_to. You have no premium_shop method defined on your Manager model, thus the NilClass error.

    If you want to define such an association for the PremiumShop class, you must explicitly specify this.

    belongs_to :premium_shop, class_name: "PremiumShop", foreign_key: :shop_id
    

    Depending on your needs, you might also consider researching “rails single table inheritance”.

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

Sidebar

Related Questions

Was hoping I could get a bit of a hand on this login that
hey guys was hoping you could help me out, Not sure if I always
I was hoping someone could have a look and tidy this up for me;
I was hoping someone could help me out with this stupid problem I'm having
I was hoping somebody could help me with with this. I am trying to
Hoping some could direct me to a tool that i can use to monitor
I was hoping someone could shed some light on this for me... I can't
I was hoping someone could tell me if this would be bad database design:
I was hoping someone could help me with this I have data like this
was hoping you could help me out. I am trying to check if a

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.