Model Inheritence Question


#1

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


#2

On 11/20/05, Paul 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


#3

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]