【发布时间】:2011-12-17 06:24:02
【问题描述】:
我正在开发一个投票功能,允许users 使用options 创建投票questions 并允许其他users 到answer 他们
answer 模型包含一个 option_id 列,但是这两个模型不相关。
我有两个问题:
- 我的模型(如下)是否完全封装了我想要表示的内容?
-
answer控制器操作的创建方法看起来如何? (具体如何找回option_id)
注意:我从未处理过模型(answer)通过option_id 引用另一个模型(option)但两者不相关的模式
到目前为止,我有这个:
class Question < ActiveRecord::Base
belongs_to :user
has_many :options
has_many :answers
end
class Option < ActiveRecord::Base
belongs_to :question
end
class Answer < ActiveRecord::Base
belongs_to :user
belongs_to :question
end
【问题讨论】:
标签: ruby-on-rails ruby database ruby-on-rails-3 database-design