# Pedigree tree modeling RoR

**URL:** <https://www.ruby-forum.com/t/pedigree-tree-modeling-ror/81840>\
**Category:** Rails\
**Created:** [January 15, 2007, 5:37pm UTC](https://www.ruby-forum.com/t/pedigree-tree-modeling-ror/81840 "2007-01-15T17:37:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![alfredogz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/dbc845/32.png) [@alfredogz](https://www.ruby-forum.com/u/alfredogz)\
**Post date:** [January 15, 2007, 5:37pm UTC](https://www.ruby-forum.com/t/pedigree-tree-modeling-ror/81840/1 "2007-01-15T17:37:02Z")

</div>

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??

---

<div class="post-metadata">

**Author:** ![alfredogz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/dbc845/32.png) [@alfredogz](https://www.ruby-forum.com/u/alfredogz)\
**Post date:** [January 15, 2007, 6:02pm UTC](https://www.ruby-forum.com/t/pedigree-tree-modeling-ror/81840/2 "2007-01-15T18:02:16Z")

</div>

I don’t understand your question …

Is id\_sire the id of the father ? And id\_dam the id of the mother ?

---

<div class="post-metadata">

**Author:** ![alfredogz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/dbc845/32.png) [@alfredogz](https://www.ruby-forum.com/u/alfredogz)\
**Post date:** [January 15, 2007, 6:06pm UTC](https://www.ruby-forum.com/t/pedigree-tree-modeling-ror/81840/3 "2007-01-15T18:06:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![alfredogz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/dbc845/32.png) [@alfredogz](https://www.ruby-forum.com/u/alfredogz)\
**Post date:** [January 16, 2007, 5:29am UTC](https://www.ruby-forum.com/t/pedigree-tree-modeling-ror/81840/4 "2007-01-16T05:29:09Z")

</div>

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? %\>
