# Problem with has\_many

**URL:** <https://www.ruby-forum.com/t/problem-with-has-many/134181>\
**Category:** Rails\
**Created:** [April 8, 2008, 5:14pm UTC](https://www.ruby-forum.com/t/problem-with-has-many/134181 "2008-04-08T17:14:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sigma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dec6dc/32.png) [@sigma](https://www.ruby-forum.com/u/sigma)\
**Post date:** [April 8, 2008, 5:14pm UTC](https://www.ruby-forum.com/t/problem-with-has-many/134181/1 "2008-04-08T17:14:46Z")

</div>

Hi all

I’ve got a message table, where the sender and the receiver are stored  
(sender\_user\_id, receiver\_user\_id)

How must i declare this dependencies in the user and message model?

I’ve got the following one:  
has\_many :messages, :foreign\_key=\> ‘receiver\_user\_id’

but how to declare the secound one?

Thank you for your help!

Greets

---

<div class="post-metadata">

**Author:** ![sigma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dec6dc/32.png) [@sigma](https://www.ruby-forum.com/u/sigma)\
**Post date:** [April 8, 2008, 5:38pm UTC](https://www.ruby-forum.com/t/problem-with-has-many/134181/2 "2008-04-08T17:38:55Z")

</div>

On 8 Apr 2008, at 16:14, Christoph Thommen wrote:

> ‘receiver\_user\_id’
> 
> but how to declare the secound one?

I would probably do

has\_many :received\_messages, :class\_name =\> “Message”, :foreign\_key =\>  
‘receiver\_user\_id’  
has\_many :sent\_messages, :class\_name =\> “Message”, :foreign\_key =\>  
‘sender\_user\_id’

Fred
