# Inheritance not using STI

**URL:** <https://www.ruby-forum.com/t/inheritance-not-using-sti/105648>\
**Category:** Rails\
**Created:** [June 1, 2007, 12:04am UTC](https://www.ruby-forum.com/t/inheritance-not-using-sti/105648 "2007-06-01T00:04:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![daveh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/85e7bf/32.png) [@daveh](https://www.ruby-forum.com/u/daveh)\
**Post date:** [June 1, 2007, 12:04am UTC](https://www.ruby-forum.com/t/inheritance-not-using-sti/105648/1 "2007-06-01T00:04:19Z")

</div>

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  
socks,  
shirts and pants and they’re having a great time. When displaying all  
items  
in their cart, each line item is of a different product type  
technically,  
but yet they all share a few of the same attributes (material\_used,  
color,  
manufacture).

Would it be wise to create a general Product class that stores the  
common  
attributes which is used for the initial @user.products query (assuming  
you  
have a valid User object and the superclass Product exists), and then  
each  
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  
etc…

I guess I’m a little confused on the best way to keep it simple (as well  
as  
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  
what  
kind of attributes they have and then display the proper info. I’d like  
to  
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  
project.  
I’m thinking more of going the class table inheritance route, but I’m  
not  
sure.  
([P of EAA: Class Table Inheritance](http://www.martinfowler.com/eaaCatalog/classTableInheritance.html)).

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

Thank you,  
Dave

---

<div class="post-metadata">

**Author:** ![daveh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/85e7bf/32.png) [@daveh](https://www.ruby-forum.com/u/daveh)\
**Post date:** [June 1, 2007, 10:25am UTC](https://www.ruby-forum.com/t/inheritance-not-using-sti/105648/2 "2007-06-01T10:25:30Z")

</div>

Dave,

Have a look to: [http://clti.rubyforge.org/](http://clti.rubyforge.org/)

Jean-Etienne

> **[Domain2.hu](https://domain2.hu/www.woa.hu)**
>
> www.woa.hu megvásárolható domain a kiemelt domain nevek piacterén.

---

<div class="post-metadata">

**Author:** ![daveh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/85e7bf/32.png) [@daveh](https://www.ruby-forum.com/u/daveh)\
**Post date:** [June 1, 2007, 10:41am UTC](https://www.ruby-forum.com/t/inheritance-not-using-sti/105648/3 "2007-06-01T10:41:25Z")

</div>

Hey,

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://  
[clti.rubyforge.org/](http://clti.rubyforge.org/)).  
As discussed here ([http://groups.google.de/group/rubyonrails-talk/](http://groups.google.de/group/rubyonrails-talk/)  
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.

Regards,

Mike

---

<div class="post-metadata">

**Author:** ![daveh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/85e7bf/32.png) [@daveh](https://www.ruby-forum.com/u/daveh)\
**Post date:** [June 1, 2007, 4:23pm UTC](https://www.ruby-forum.com/t/inheritance-not-using-sti/105648/4 "2007-06-01T16:23:13Z")

</div>

Thanks Jean-Etienne and Mike for the info. I’ll take a look at  
[clti.rubyforge.org](http://clti.rubyforge.org). I know it doesn’t work with oracle, but it might be  
easily extended.

-Dave
