# Model Inheritence Question

**URL:** <https://www.ruby-forum.com/t/model-inheritence-question/48466>\
**Category:** Rails\
**Created:** [November 21, 2005, 12:12am UTC](https://www.ruby-forum.com/t/model-inheritence-question/48466 "2005-11-21T00:12:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![paul.marsh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/958977/32.png) [@paul.marsh](https://www.ruby-forum.com/u/paul.marsh)\
**Post date:** [November 21, 2005, 12:12am UTC](https://www.ruby-forum.com/t/model-inheritence-question/48466/1 "2005-11-21T00:12:38Z")

</div>

I am looking on how I could do something like the following,

Foo \< AR::Base  
Bar \< Foo.

I would like to list all Foo’s, but because Bar.is\_a? Foo == true I  
would like Bars to list as well.

Any ideas? Or pointers in the right direction? I know there is a ruby  
command to list subclasses, or ancestors (don’t have my pickaxe handy)  
but seem to remember it listing only models that are also have been  
used in a method.

Thanks,  
Paul

---

<div class="post-metadata">

**Author:** ![paul.marsh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/958977/32.png) [@paul.marsh](https://www.ruby-forum.com/u/paul.marsh)\
**Post date:** [November 21, 2005, 6:50am UTC](https://www.ruby-forum.com/t/model-inheritence-question/48466/2 "2005-11-21T06:50:48Z")

</div>

On 11/20/05, Paul [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I am looking on how I could do something like the following,
> 
> Foo \< AR::Base  
> Bar \< Foo.
> 
> I would like to list all Foo’s,

Foo.find(:all)

I suppose you want to do something fancier than that, eh?

-Peter

---

<div class="post-metadata">

**Author:** ![paul.marsh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/958977/32.png) [@paul.marsh](https://www.ruby-forum.com/u/paul.marsh)\
**Post date:** [November 21, 2005, 12:09pm UTC](https://www.ruby-forum.com/t/model-inheritence-question/48466/3 "2005-11-21T12:09:50Z")

</div>

Paul wrote:

> but seem to remember it listing only models that are also have been  
> used in a method.

Not precisely sure what you want to do, but ancestors lists all  
classes the receiver inherit from:

irb(main):001:0\> require ‘active\_record’  
=\> true  
irb(main):002:0\> class Table \< ActiveRecord::Base  
irb(main):003:1\> end  
=\> nil  
irb(main):004:0\> class Table2 \< Table  
irb(main):005:1\> end  
=\> nil  
irb(main):007:0\> Table2.ancestors  
=\> [Table2, Table, ActiveRecord::Base, ActiveRecord::Acts::NestedSet,  
ActiveRecord::Acts::List, ActiveRecord::Acts::Tree,  
ActiveRecord::Reflection, ActiveRecord::Transactions,  
ActiveRecord::Aggregations, ActiveRecord::Associations,  
ActiveRecord::Timestamp, ActiveRecord::Callbacks, ActiveRecord::Locking,  
ActiveRecord::Validations, ClassInheritableAttributes, Object, Kernel]
