I have a message model (Message) and this models as a userTo and userFrom, so two references to User. How can i write the migration? My user model is User.
Thank you
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In the migration, create two different columns for each kind of user. For example:
Then in the model, that’s where the logic to map each column to the User class happens:
Of course, use your own words for
senderandreceiver, but Rails will automatically associatesenderto thesender_idcolumn (and the same logic forreceiver)You will then be able to interact with both user
user.senderanduser.receiver.