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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:18:32+00:00 2026-05-22T12:18:32+00:00

So this is probably a fairly easy question to answer but here goes anyway.

  • 0

So this is probably a fairly easy question to answer but here goes anyway.

I want to have this view, say media_objects/ that shows a list of media objects. Easy enough, right? However, I want the list of media objects to be a collection of things that are subtypes of MediaObject, CDMediaObject, DVDMediaObject, for example. Each of these subtypes needs to be represented with a db table for specific set of metadata that is not entirely common across the subtypes.

My first pass at this was to create a model for each of the subtypes, alter the MediaObject to be smart enough to join into those tables on it’s conceptual ‘all’ behavior. This seems straightforward enough but I end up doing a lot of little things that feel not so rails-O-rific so I wanted to ask for advice here.

I don’t have any concrete code for this example yet, obviously, but if you have questions I’ll gladly edit this question to provide that information…

thanks!

  • 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-22T12:18:33+00:00Added an answer on May 22, 2026 at 12:18 pm

    Creating a model for each sub-type is the way to go, but what you’re talking about is multiple-table inheritance. Rails assumes single-table inheritance and provides really easy support for setting it up. Add a type column to your media_objects table, and add all the columns for each of the specific types of MediaObject to the table. Then make each of your models a sub-class of MediaObject:

    class MediaObject < ActiveRecord::Base
    
    end
    
    class CDMediaObject < MediaObject
    
    end
    

    Rails will handle pulling the records out and instantiating the correct subclass, so that when you MediaObject.find(:all) the results will contain a mixture of instances of the various subclasses of MediaObject.

    Note this doesn’t meet your requirement:

    Each of these subtypes needs to be represented with a db table for specific set of metadata that is not entirely common across the subtypes.

    Rails is all about convention-over-configuration, and it will make your life very easy if you write your application to it’s strengths rather than expecting Rails to adapt to your requirements. Yes, STI will waste space leaving some columns unpopulated for every record. Should you care? Probably not; database storage is cheap, and extra columns won’t affect lookup performance if your important columns have indexes on them.

    That said, you can setup something very close to multiple-table inheritance, but you probably shouldn’t.

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

Sidebar

Related Questions

Hey guys, sorry for this probably fairly simple question but I'm starting to get
This is probably a fairly basic question but I haven't managed to find anything
What I'm trying to do is fairly simple. I have two classes: public class
Hi I have an application which after login, loads a main activity which contains
Suppose we have buyers and sellers that are trying to find each other in
Why does this throw an error? myTest :: Int -> [Int] myTest a |
I'm working on an ASP.NET MVC site, using EF4 and Automapper. I'm making good
I'm looking into building an application for a car dealership. The biggest challenge I
Currently working on re-writing several interfaces and looking at what options there are for
Please excuse the awkward title I'll try my best to explain my peculiar problem.

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.