Pedigree tree modeling RoR

I modeling a pedigree web page:

Model: Animals
id
name
id_sire
id_dam

id_sire is a animal
id_dam is a animal too, then how can I show the list of the model
Animal??

1 Tino Rito Princesa
2 Princesa - -
3 Rito - -

Is it posible do it??

I don’t understand your question …

Is id_sire the id of the father ? And id_dam the id of the mother ?

Cédric H. wrote:

I don’t understand your question …

Is id_sire the id of the father ? And id_dam the id of the mother ?

Yes, they are…

the table look like:

1 Tino 2 3
2 Princesa null null
3 Rito null null

but i wanna list with respective name.

I think you want to declare your model this way:

class Animal < ActiveRecord::Base

belongs_to :sire, :class_name => ‘Animal’, :foreign_key => ‘id_sire’
belongs_to :dam, :class_name => ‘Animal’, :foreign_key => ‘id_dam’

end

then in your view:

id, name, sire, dam
<%= animal.id %> <%= animal.name %> <%= animal.sire.name unless
animal.sire.nil? %> <%= animal.dam.name unless animal.dam.nil? %>