# Could I use inherited model?

**URL:** <https://www.ruby-forum.com/t/could-i-use-inherited-model/106085>\
**Category:** Rails\
**Created:** [June 6, 2007, 9:24am UTC](https://www.ruby-forum.com/t/could-i-use-inherited-model/106085 "2007-06-06T09:24:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Magicloud](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f17d59/32.png) [@Magicloud](https://www.ruby-forum.com/u/Magicloud)\
**Post date:** [June 6, 2007, 9:24am UTC](https://www.ruby-forum.com/t/could-i-use-inherited-model/106085/1 "2007-06-06T09:24:17Z")

</div>

Like I have a class A and a class B, A \< B, B \< ActiveRecord::Base. as  
and bs are two different table in database, as has bs’s columns. (I  
use postgresql’s inherit table).

Now I do ‘A.find(:all, conditions =\> “acol1 = 0”)’, acol1 does exists  
in bs.  
“ActiveRecord::StatementInvalid” throwed, bs does not have acol1  
column. “select \* from bs where (acol1 = 0)”

How to resolve this? Why A.find does not do “select \* from as where  
(acol1 = 0)”?  
Thanks.

---

<div class="post-metadata">

**Author:** ![Magicloud](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f17d59/32.png) [@Magicloud](https://www.ruby-forum.com/u/Magicloud)\
**Post date:** [June 6, 2007, 11:30am UTC](https://www.ruby-forum.com/t/could-i-use-inherited-model/106085/2 "2007-06-06T11:30:34Z")

</div>

Magicloud wrote:

> (acol1 = 0)"?  
> Adding

set\_table\_name ‘as’

to the A class may get it working.

–  
We develop, watch us RoR, in numbers too big to ignore.

---

<div class="post-metadata">

**Author:** ![Magicloud](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f17d59/32.png) [@Magicloud](https://www.ruby-forum.com/u/Magicloud)\
**Post date:** [June 6, 2007, 7:04pm UTC](https://www.ruby-forum.com/t/could-i-use-inherited-model/106085/3 "2007-06-06T19:04:08Z")

</div>

ActiveRecord supports single table inheritance. The table name is  
taken from the immediate subclass of ActiveRecord::Base.

You can place a type column in this table to support Ruby subclasses,  
but all columns and all records must be in one table.

The only other option (which I have not tried) is to mark the  
immediate subclass of ActiveRecord::Base as abstract in which case all  
subclasses will each be in their own table. But, then all  
associations that reference any of those classes must be polymorphic  
associations.

Michael
