Search code examples
ruby-on-railsruby-on-rails-3relationships

Rails Hash/Array Relationships


So I have three models going on.

Model 1: Questions with a has_many relationships to Answers

Model 2: Answers (belongs_to Questions)

Model 3: A User

Here's my conundrum. Upon answering my questions, I would like my user to have a property that indicates their answers for every question, so I can compare them later. How would I go about doing this?


Solution

  • Add a user_id field to answers and set its value to match the id of the user that provided the answers. This way you can later query the answers that belong to a/the particular user.