开发者

Structuring question and answer database in RoR

开发者 https://www.devze.com 2023-01-13 14:00 出处:网络
I\'m thinking about how to structure the database tables on my Ruby on Rails app. It\'s an app 开发者_JS百科that will allow academic surveys to be sent to a student population. But as I haven\'t had a

I'm thinking about how to structure the database tables on my Ruby on Rails app. It's an app 开发者_JS百科that will allow academic surveys to be sent to a student population. But as I haven't had a lot of experience with database design, I don't know the answer to the following:

Which of the following should my tables look like?

Survey
  ID
  questions (has_many)
  etc...

Questions
  ID
  question (string)
  response (has_many)

Answers
  ID
  questions (belongs_to)
  response-text (string)

or...

Survey
  ID
  questions (has_many)
  etc...

Questions
  ID
  question (string)
  responses (string, or hash, or something. Don't even know if this is possible.)

Or should I do something completely different?


surveys have questions. questions have answers

Survey
  has_many :questions
  has_many :answers, :through => :questions
end

Question
  belongs_to :survey
  has_many :answers
end

Answer
  belongs_to :question
end
0

精彩评论

暂无评论...
验证码 换一张
取 消