Forum: Ruby on Rails Inheritance not using STI

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Dave H. (Guest)
on 2007-06-01 02:04
(Received via mailing list)
Hi there,

I have a question about inheritance in Rails.

Say you have 3 tables:
1. pants
2. shirts
3. socks

Each table has different attributes, but they do share some of the same
attributes respectively in each table:

Common attributes amongst all the tables:
1. material_used
2. color
3. manufacture

Different attributes:
1. pants
   - length
   - waist_size
2. shirts
   - sleeve_length
   - neck_size
3. socks
   - foot_size
   - is_striped (say this is a boolean value)

Now say someone is browsing through your online clothing store buying
shirts and pants and they're having a great time. When displaying all
in their cart, each line item is of a different product type
but yet they all share a few of the same attributes (material_used,

Would it be wise to create a general Product class that stores the
attributes which is used for the initial @user.products query (assuming
have a valid User object and the superclass Product exists), and then
product type would inherit from Product.
class Product;end # initialize common attributes somehow
class Pants < Product;end # specify specific attributes
class Shirts < Product;end # specify specific attributes
class Socks < Product;end # specify specific attributes

I guess I'm a little confused on the best way to keep it simple (as well
how to create the Product class, which I think is a proxy class hooked
up to
ActiveRecord somehow... ?) when iterating through the clothes to see
kind of attributes they have and then display the proper info. I'd like
keep as much business logic out of the view as possible. Obviously Pants
don't have an attribute called "foot_size". I don't have the option of
changing the database tables too much, so STI is a no-go for this
I'm thinking more of going the class table inheritance route, but I'm

Are there any tutorials that cover what I'm talking about? If it
I'm stuck with Oracle. Did any of this make sense or am I on crazy

Thank you,
Jean-Etienne D. (Guest)
on 2007-06-01 12:25

Have a look to:

Mike (Guest)
on 2007-06-01 12:41
(Received via mailing list)

right now Rails doesn't seem to support CTI. There's a plugin for
PostgreSQL, but if you are stuck to Oracle this might not work (http://
As discussed here (
browse_thread/thread/8d4159425d094cd9), the only way is to create a
full table for all subclasses and/or set the relations manually.
I'm now running in this problem too with a project, so I maybe write
later, how I fixed it.


Dave H. (Guest)
on 2007-06-01 18:23
(Received via mailing list)
Thanks Jean-Etienne and Mike for the info. I'll take a look at I know it doesn't work with oracle, but it might be
easily extended.

This topic is locked and can not be replied to.