I have a private message model that relates to two users, how do I setup an association so that PM.sender is the sender’s user model and PM.receiver is recipient’s user model? (so that I can call PM.sender.username etc.)
I have a sender_id and receiver_id field.
Assuming model classes
MessageandUser, in yourMessagemodel:Because the class name can’t be deduced from the association name the explicit
:class_nameis required.Update: Having just checked, the
:foreign_keyparameter shouldn’t be required as long as the name of the foreign key is the name of the association followed by_id, which it is in this case.