# Two columns reference to the same table

**URL:** <https://www.ruby-forum.com/t/two-columns-reference-to-the-same-table/110386>\
**Category:** Rails\
**Created:** [July 25, 2007, 11:24pm UTC](https://www.ruby-forum.com/t/two-columns-reference-to-the-same-table/110386 "2007-07-25T23:24:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![cfingerh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f14d63/32.png) [@cfingerh](https://www.ruby-forum.com/u/cfingerh)\
**Post date:** [July 25, 2007, 11:24pm UTC](https://www.ruby-forum.com/t/two-columns-reference-to-the-same-table/110386/1 "2007-07-25T23:24:20Z")

</div>

I have one table with the users (id, name, birthday) and another table  
with messages from one user to another. The problem is, in the message  
table I need to create a relationship for the sender and the receiver  
like this:

messages =\> id , text, date, user\_id\_receiver, user\_id\_sender

¿ How do I have to name those columns (user\_id\_sender,  
sender\_user\_id,…)?  
¿What do I have to write in the model file message.rb for linking  
both tables?  
I need to get the name of the sender and the receiver of the message  
\<%=message.user.name %\> ???

thanks
