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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T11:54:05+00:00 2026-06-02T11:54:05+00:00

So we all know that rails’ STI (single table inheritance) is icky because it

  • 0

So we all know that rails’ STI (single table inheritance) is icky because it leads to a cluttered data model and suboptimal database.

However PostgreSQL seems to handle inheritance quite beautifully!

Is there a way to get rails’ nice clean STI API while utilizing Postgres inheritance instead of painfully wide tables and “type” columns?

  • 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-02T11:54:07+00:00Added an answer on June 2, 2026 at 11:54 am

    In short – no there no nice clean STI API for what you are trying to accomplish as of right now.

    I actually looked into that a about a year ago and came to a conclusion that it is not a good idea for several reasons:

    1. If you want to utilize PostgreSQL specific features – you are basically marrying yourself to that DB. Don’t get me wrong PostgreSQL is a great DB and I’ve used it on a number of occasions, but you are going to be stuck with that DB and app design.
    2. Most likely if you start using DB specific features you’ll either end up implementing them manually ( running some kind of commands on the DB or using GUI) or writing some kind of script that you will have to invoke whenever you are running db:migrate ( you will have to do it if you want to do proper testing). After awhile it becomes cumbersome and annoying.
    3. If you find that you are more and more annoyed with, to quote you “painfully wide tables and “type” columns” then:
      • Your table design needs to be rethought and redone
      • Your models may not be a good candidates for STI
      • You just have to live with it.

    Most IT problems really come down to this: Effort vs Benefit.

    In your case you should ask yourself this question:

    • How much time do you want to spend on implementing a better STI
      structure if it will only speed up your raw SQL query by a few seconds? Maybe it’s better to write a more explicative SQL query? Most applications don’t grow to the size where it really becomes an issue. But it maybe different in your case.

    P.S.:

    Also a quick tip on structuring STI in your app: If you find that you have a lot of models that use STI like a ProductCategory, CommentCategory, PhoneCategory, ClientCategory that all inherit from Cateogory – I tend to organize them in folders inside model directory. Then in application.rb just add a line: config.autoload_paths += Dir[Rails.root.join('app', 'models', '{**/**}')]

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

Sidebar

Related Questions

We all know that a hash table has O(1) time for both inserts and
I know that in Rails all ActiveRecord callbacks are executed inside transaction. So if
we all know that the cell in uitableview can be resued, but i am
We all know that RAW pointers need to be wrapped in some form of
We all know that commenting our code is an important part of coding style
We all know that having a good note taking tool is important as a
We all know that deadlines and/or critical bugfixes and make us forget a bit
We all know that you can overload a function according to the parameters: int
We all know that CSS sprite images are great to reduce the amount of
We all know that most applications out there assume class names to follow the

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.