Friday 15 June 2012

activerecord - help with rails associations -


I want to implement a messaging system for my app.

I have users

What exactly should I do? Can foreign users create a message model with foreign key ?? What would be the most accomplished way of doing this?

My concern is that if I ask "message.user" then I do not know what the id is the receiver of the message receiver receiving

Approprately use two different foreign keys by the name

Viewing a message model with the foreign key Sender_id and receiver_id you can:

/ P>

  class message & lt; ActiveRecord :: base is_to: sender, class_name = & gt; "User",: foreign_key = & gt; "Sender_id" is_to: receiver,: class_name = & gt; "User",: foreign_key = & gt; "Receiver_id" end  

You will now be able to refer to the sender of a message using message.sender and by using message.receiver Receiver .


No comments:

Post a Comment