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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:26:31+00:00 2026-06-10T22:26:31+00:00

I’m working on a Rails project OldApp that’s using STI for some class Foo.

  • 0

I’m working on a Rails project OldApp that’s using STI for some class Foo.
At the moment we have a big, incremental, rewrite going on. To ease the pain we chose a rather unconventional approach. The new, namespaced, application NewApp lives as an engine in OldApp for now.

The models we’re going to reuse in NewApp have been created in NewApp and OldApp now uses these models as their parent classes. Why? Now we can move and refactor code from OldApps models to the new ones, OldApp still works, the tests from OldApp ensure that the refactoring in NewApp doesn’t break stuff and OldApp basically works as a todo-list (if everything from OldApp is gone, we’re done). However 😉

The problem is, STI kinda kills this (otherwise surprisingly nicely working) approach at the moment.

   class OldApp::Foo < NewApp::Foo; end
   class NewApp::Foo < ActiveRecord::Base; end

   # in the console
   OldApp::Foo.count #=> SELECT COUNT(*) FROM `foos` WHERE `foos`.`type` IN ('Foo')
   NewApp::Foo.count #=> SELECT COUNT(*) FROM `foos`

of course, OldApp::Foo does this, because it’s assuming it’s just a STIish subclass of NewApp::Foo and not the base Foo class for NewApp. Disabling STI completly for Whatever::Foo doesn’t work either because, well, in fact we are using STI for Foo.

I’m basically looking for something to tell NewApp::Foo that it’s the base class for the STI chain.

Does this make sense? A little hard to explain…

  • 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-10T22:26:33+00:00Added an answer on June 10, 2026 at 10:26 pm

    Using an abstract base class and let inherit OldApp::Foo and NewApp::Foo from it would do the trick:

    class NewApp::FooBase < ActiveRecord::Base
        self.abstract_class = true
    end
    
    class NewApp::Foo < NewApp::FooBase; end
    class OldApp::Foo < NewApp::FooBase; end
    

    You would put all your refactored code in the base class so that OldApp::Foo and NewApp::Foo act as starting point for STI.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have thousands of HTML files to process using Groovy/Java and I need to
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.