# RoR DB design question

**URL:** <https://www.ruby-forum.com/t/ror-db-design-question/86738>\
**Category:** Rails\
**Created:** [February 25, 2007, 8:10am UTC](https://www.ruby-forum.com/t/ror-db-design-question/86738 "2007-02-25T08:10:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dougd1101](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ba9def/32.png) [@dougd1101](https://www.ruby-forum.com/u/dougd1101)\
**Post date:** [February 25, 2007, 8:10am UTC](https://www.ruby-forum.com/t/ror-db-design-question/86738/1 "2007-02-25T08:10:14Z")

</div>

I am VERY new to the RoR game, but quickly becoming a convert.

I am doing a discussion board application in RoR just to learn RoR.  
You all are very familiar with the discussion board domain. Someone  
starts a new thread, someone comments on that thread and or starts a  
new thread and so on…

I have a table called comments. This table follows all the Railisms  
but I have a few questions. What would I call a field in the comments  
table that refers BACK to itself (ie the comments table)? This is for  
child comments. This would maintain a child/parent relationship for  
each of the comments.

Then would I add  
belongs\_to :comment  
has\_many :comments

in the comments.rb

Thanks.

---

<div class="post-metadata">

**Author:** ![dougd1101](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ba9def/32.png) [@dougd1101](https://www.ruby-forum.com/u/dougd1101)\
**Post date:** [February 25, 2007, 8:51am UTC](https://www.ruby-forum.com/t/ror-db-design-question/86738/2 "2007-02-25T08:51:16Z")

</div>

Hi, I would highly recommend going through the AWDwRv2 before  
embarking on your application. This would help you get the necessary  
foundation to begin rails development. Anyway, the term or phrase  
that you’re looking for is called a self referential relationship.

Good luck,

-Conrad

---

<div class="post-metadata">

**Author:** ![dougd1101](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ba9def/32.png) [@dougd1101](https://www.ruby-forum.com/u/dougd1101)\
**Post date:** [February 26, 2007, 8:22pm UTC](https://www.ruby-forum.com/t/ror-db-design-question/86738/3 "2007-02-26T20:22:49Z")

</div>

On 2/25/07, Conrad T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi, I would highly recommend going through the AWDwRv2 before  
> embarking on your application. This would help you get the necessary  
> foundation to begin rails development. Anyway, the term or phrase  
> that you’re looking for is called a self referential relationship.
> 
> Good luck,
> 
> -Conrad

And the specific column you’re looking for is called comment\_id (you can  
actually name it anything you want via the :foreign\_key =\>  
‘some\_other\_column\_name\_here’, but the default is comment\_id)
