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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:46:52+00:00 2026-06-17T10:46:52+00:00

Background I have a rails 3 app that has a model named A with

  • 0

Background

I have a rails 3 app that has a model named A with the correspondent table as. Now I need a new model B that works exactly like A but has some other associations and methods (besides those in A).

Problem

I decided to use STI (Single Table Inheritance). I know I could do something like A < BaseModel and B < BaseModel, but there’s already a lot of code assuming a table named as and it would require too much work.

So I’m trying to do B < A, where A is not abstract. I added the type column to as. Now the model B works perfect, but the model A doesn’t know anything about inheritance and completely ignores the type column, so when I do A.create! it says that the column type cannot be empty. Also A.all returns B rows too.

What I’ve tried

  • Using the default value A for the type column. this works but only solves a part of the problem
  • Using a default scope in the A model. the problem with this approach is that it filters out all B rows for both models

Questions

  • How can I accomplish B < A in rails, where none of the models is abstract?
  • Are there any other nice alternatives?
  • 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-17T10:46:53+00:00Added an answer on June 17, 2026 at 10:46 am

    The easiest solution might be to create a new base class and have both A and B extend it.

    The base class would set its table name to point to your current A table (as):

    class NewBaseClass < ActiveRecord::Base
      self.table_name = `as`
    end
    
    class A < NewBaseClass
      # ...
    end
    
    class B < NewBaseClass
      # ...
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background I have a dimension table that has a single record for each day.
I have a Ruby on Rails app that needs process many background jobs simultaneously:
I have need to periodically run a background task in my rails app. I've
Background I'm using the acts_as_list gem in a rails app my posts table has
Background I have an app that I recently updated to Rails 3.2.1 (from Rails
I have an operation in my Heroku-hosted Rails app that runs in a background
Background Currently, I am working on a Rails application. I have different products that
Right now I'm building a project management app in rails, here is some background
Right now I'm building a project management app in rails, here is some background
I have a few data values that I need to store on my rails

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.