I’m learning rails and I’m trying to figure out database associations. If I have a database table with say Users that has an id, name, email, etc. and a Message table with the message, a sender (User) and recipient (also a User), how do I set up the migration and the models. Here, I’m using Rails 3.1. I’m pretty sure I can do it with just one User in the Message table with the references:User in the migration, but I’m not sure how to set up two of them.
Share
Some resources to get you started: Rails Tutorial: User Model RoR Guides: Migrations
First make your user migration
Then your messages migration
Then in your Messages model (/app/models/messages.rb)
And in your User model (/app/models/users.rb)
Obviously this is a rough sketch of what needs to happen, but that should get you started!