[Rails] Single Table inheitance doesn't show subclasses ?

Marcus Ob mrqzzz at yahoo.it
Sun Jan 1 18:40:27 GMT 2006


Hi, I am a Rails noob.

Suppose you have:

---
class Animal < ActiveRecord::Base
end

class Mammal < Animal
end

class Cow < Mammal
end
---

I provide Animal,Mammal and Cow controllers with the scaffolding, just 
to test and to fill up the Animal table. I can see the "type" column 
getting it's value set with the class name.
So far, soo good.

Now, since listing Animals is showing all animals in the table 
(including Mammals and Cows) i thought that listing Mammals would show 
me all Mammals *and* Cows, but i see only recods marked "Mammal" in the 
"type" column (and no Cows).

I understand that Rails doesn't select descendants of a class when 
listing it's elements, and i understand it could be more practical that 
way in most cases.

But how can i tell Rails to build the query including in the selection 
also any descendants?

thanks,
Happy new year,
Marcus.
(sorry for my poor english)

-- 
Posted via http://www.ruby-forum.com/.


More information about the Rails mailing list