Forum: Ruby on Rails Problem with inheritance and find

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.
292e825e3d670ee973e512801e5071a4?d=identicon&s=25 joserwan (Guest)
on 2008-11-11 16:41
(Received via mailing list)
Hi,

I've got 3 classes :

class Person < ActiveRecord:Base
end

class Man < Person
end

class Father < Man
end

When I call Man.all, I expect to have men and fathers, but I don't.
When I call Person.all, I have people, men and fathers...

Do I have to redefine the find method of the Father's class ???
Did I break some thing ? I'm pretty sure it worked before, but I
really don't know what I could have done to break it.

I thought it could be an issue from Rails 2.1.2, but I got the same
one with rails 2.1.1.


Please help !
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-11-11 17:08
(Received via mailing list)
On Nov 11, 3:40 pm, joserwan <joser...@gmail.com> wrote:
> class Father < Man
> one with rails 2.1.1.
>

This is a quirk of single table inheritance. If you use
require_dependency to force all the subclasses of person to be loaded
(eg at the bottom of person.rb) then it should work fine.

Fred
292e825e3d670ee973e512801e5071a4?d=identicon&s=25 joserwan (Guest)
on 2008-11-11 21:01
(Received via mailing list)
Works fine, thank you very much !
292e825e3d670ee973e512801e5071a4?d=identicon&s=25 joserwan (Guest)
on 2008-11-11 21:04
(Received via mailing list)
In facts, as Person.all gave me Men and Fathers, I had

require_dependency 'father' in the Man class.
This topic is locked and can not be replied to.