Forum: Ruby on Rails A problem w/ association testing?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Daniel F. (Guest)
on 2007-06-04 10:47
(Received via mailing list)
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!
Jacob A. (Guest)
on 2007-06-04 12:59
(Received via mailing list)
DanielFischer.com wrote:
> 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.
This topic is locked and can not be replied to.