开发者

Structuring question and answer database in RoR

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜