# Single table inheritance problem

**URL:** <https://www.ruby-forum.com/t/single-table-inheritance-problem/111273>\
**Category:** Rails\
**Created:** [August 4, 2007, 6:26pm UTC](https://www.ruby-forum.com/t/single-table-inheritance-problem/111273 "2007-08-04T18:26:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dark-omen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c68b51/32.png) [@dark-omen](https://www.ruby-forum.com/u/dark-omen)\
**Post date:** [August 4, 2007, 6:26pm UTC](https://www.ruby-forum.com/t/single-table-inheritance-problem/111273/1 "2007-08-04T18:26:53Z")

</div>

I am having trouble getting a single table inheritance to work. This is  
what I tried I made a base model called Product, made the migration with  
all columns for every type of product that I want to create. Also in my  
migration I made a column called type to differentiate between classes.  
Also, from what I read in AWD I put the :force -\> true option after the  
table name.  
So now I ran the rake db migrate and it made the table. Then I made a  
class called DealProduct and I put it in the models folder as  
deal\_product.rb. I also made it inherit the base class Product. So I  
had:

DealProduct \< Product  
end

So then I made a controller called deal\_product, and then I tried  
generating the scaffolding for the controller and the DealProduct  
controller, and it throws an error saying “Before updating scaffolding  
from new DB schema, try creating a table for your model (DealProduct),”  
but if I have it inherited from my base class Product, why is it  
throwing me this error, shouldn’t it know that it already has one? And  
am I even doing this right, is there anything that would make this not  
work?

---

<div class="post-metadata">

**Author:** ![dark-omen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c68b51/32.png) [@dark-omen](https://www.ruby-forum.com/u/dark-omen)\
**Post date:** [August 4, 2007, 6:50pm UTC](https://www.ruby-forum.com/t/single-table-inheritance-problem/111273/2 "2007-08-04T18:50:47Z")

</div>

OOOOO, I got it, so I wasn’t generating the model first, I was just  
creating a new class. So what I did was generate the model, then in the  
model I put self.inheritance\_column = ‘type’ (don;t know if I needed  
this, but I saw it in the rails API), and then I ran rake db:migrate  
again to create the table. Now I generated the scaffolding for the  
controller and model and it worked !!! 🙂

But if anyone could tell me if I need that self.inheritance\_column  
declaration in my child classes that would be great.
