Two foreign keys with ActiveRecord? [rails] -


I have a user class in the context of the message class in the message class user_id (which is the sender ) And a receiver_id . So in the user category I have

  is_im: message is_my: message, foreign_key => "Receiver_ID"  

and then in message class I have

  related_to: user  

first relation - - < Code> via user_id - goes perfectly well Message message for other relationships I do not have to think anything in class. If the message table is created with both user_id and receiver_id , then there is support.

Is this also possible?

In addition, I did not know how to get a received message from a user ... or the user who received the message :)

[I know that I would like to use a sender table and a receiver table and a message table and maybe a group of other tables (a conversation table!), But I want to do it in this way, for its joke, this application will be used only for learning. ]

Also important Full: Where, for Docs? In your user category,

  has_many: message has_many: received_messages,: foreign_key = & gt; "Receiver_id" ,: class_name = & gt; "Message"  

In your message class:

  related_ to: related to user's value: receiver, class_name = & gt; "User" @ user = user.fost@user.message.com @ user.resever_smesses  

Comments