# A problem w/ association testing?

**URL:** <https://www.ruby-forum.com/t/a-problem-w-association-testing/105878>\
**Category:** Rails\
**Created:** [June 4, 2007, 8:47am UTC](https://www.ruby-forum.com/t/a-problem-w-association-testing/105878 "2007-06-04T08:47:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![arachnd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/278dde/32.png) [@arachnd](https://www.ruby-forum.com/u/arachnd)\
**Post date:** [June 4, 2007, 8:47am UTC](https://www.ruby-forum.com/t/a-problem-w-association-testing/105878/1 "2007-06-04T08:47:45Z")

</div>

[http://pastie.caboo.se/67535](http://pastie.caboo.se/67535)

I have a problem w/ my associations, you can look at it on my pastie  
up above.

Please help me out, thanks!

---

<div class="post-metadata">

**Author:** ![arachnd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/278dde/32.png) [@arachnd](https://www.ruby-forum.com/u/arachnd)\
**Post date:** [June 4, 2007, 10:59am UTC](https://www.ruby-forum.com/t/a-problem-w-association-testing/105878/2 "2007-06-04T10:59:02Z")

</div>

[DanielFischer.com](http://DanielFischer.com) wrote:

> [Parked at Loopia](http://pastie.caboo.se/67535)
> 
> I have a problem w/ my associations, you can look at it on my pastie  
> up above.
> 
> Please help me out, thanks!

SQLite tells you:

no such column: messages.user\_id

As far as I can tell you only have author\_id and recipient\_id in the  
messages table. So what you need to do is to change your User model from  
has\_many :messages to has\_many :incoming\_messages and has\_many  
:outgoing\_messages or whatever and hook it up with the corresponding  
foreign keys and classes just like you do in the Message model.

If you want to find all messages you could:

class User  
def messages  
incoming\_messages + outgoing\_messages  
end  
end

–  
Cheers,

- Jacob A.
