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

  • Home
  • SEARCH
  • 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 1049763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:40:04+00:00 2026-05-16T16:40:04+00:00

I am working on a very large Rails application. We initially did not use

  • 0

I am working on a very large Rails application. We initially did not use much inheritance, but we have had some eye opening experiences from a consultant and are looking to refactor some of our models.

We have the following pattern a lot in our application:

class Project < ActiveRecord::Base
  has_many :graph_settings
end

class GraphType < ActiveRecord::Base
  has_many :graph_settings
  #graph type specific settings (units, labels, etc) stored in DB and very infrequently updated.
end

class GraphSetting < ActiveRecord::Base
  belongs_to :graph_type
  belongs_to :project
  # Project implementation of graph type specific settings (y_min, y_max) also stored in db.
end

This also results in a ton of conditionals in views, helpers and in the GraphSetting model itself. None of this is good.

A simple refactor where we get rid of GraphType in favor of using a structure more like this:

class Graph < ActiveRecord::Base
  belongs_to :project
  # Generic methods and settings
end

class SpecificGraph < Graph
  # Default methods and settings hard coded
  # Project implementation specific details stored in db.
end

Now this makes perfect sense to me, eases testing, removes conditionals, and makes later internationalization easier. However we only have 15 to 30 graphs.

We have a very similar model (to complicated to use as an example) with close to probably 100 different ‘types’, and could potentially double that. They would all have relationships and methods they inheritated, some would need to override more methods then others. It seems like the perfect use, but that many just seems like a lot.

Is 200 STI classes to many? Is there another pattern we should look at?

Thanks for any wisdom and I will answer any questions.

  • 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-16T16:40:05+00:00Added an answer on May 16, 2026 at 4:40 pm

    If the differences are just in the behavior of the class, then I assume it shouldn’t be a problem, and this is a good candidate for STI. (Mind you, I’ve never tried this with so many subclasses.)

    But, if your 200 STI classes each have some unique attributes, you would need a lot of extra database columns in the master table which would be NULL, 99.5% of the time. This could be very inefficient.

    To create something like “multiple table inheritance”, what I’ve done before with success was to use a little metaprogramming to associate other tables for the details unique to each class:

    class SpecificGraph < Graph
      include SpecificGraphDetail::MTI
    end
    
    class SpecificGraphDetail < ActiveRecord::Base
      module MTI
        def self.included(base)
          base.class_eval do
            has_one :specific_graph_detail, :foreign_key => 'graph_id', :dependent => :destroy
            delegate :extra_column, :extra_column=, :to => :specific_graph_detail
          end
        end
      end
    end
    

    The delegation means you can access the associated detail fields as if they were directly on the model instead of going through the specific_graph_detail association, and for all intents and purposes it “looks” like these are just extra columns.

    You have to trade off the situations where you need to join these extra detail tables against just having the extra columns in the master table. That will decide whether to use STI or a solution using associated tables, such as my solution above.

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

Sidebar

Related Questions

I have recently started working on a very large C++ project that, after completing
I am working on a very large scale computing library that is using STL
I'm working on a problem that requires caching paginated search results: Paginating very large
I have recently been working with someone on a project that is very ajax
I'm working on a very simple game (essentially an ice sliding puzzle), for now
I've been working on a very simple crud generator for pylons. I came up
I'm currently working on a very short project on Prolog, and just got stuck
Very often when working on an ASP.NET web site, the options View Code and
Very odd problem as this is working perfectly on our old Classic ASP site.
I'm working on keyboard input for a very basic kernel that I'm developing and

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.