Just starting to use Ruby on Rails to see what its like.
I have a user model with an id and a post model with an adderId. The adderId of the post model should be the user id of the user that created it.
How can I relate these with Ruby on Rails?
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.
The Rails convention for foreign keys would give your Post model a user_id column rather than adderId. You can break the convention, but that requires slightly more configuration, as below:
If you gave Post a user_id instead, you could do this:
I’d recommend taking a look at the Rails Guide for Active Record Associations, which covers all of the above and plenty more.