Forum: Ruby on Rails Model Inheritence Question

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
0ff4b2f49c3df249959a4560c0e16510?d=identicon&s=25 paul.marsh (Guest)
on 2005-11-21 00:12
(Received via mailing list)
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
Eea3feaacbe44706164289d068d94828?d=identicon&s=25 petermichaux (Guest)
on 2005-11-21 06:50
(Received via mailing list)
On 11/20/05, Paul <paul.marsh@gmail.com> 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
467c7c87ad5b36859a7644b9198b490a?d=identicon&s=25 leslie (Guest)
on 2005-11-21 12:09
(Received via mailing list)
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]
This topic is locked and can not be replied to.