考虑下面的协会,我需要引用Question
一个Choice
通过从连接Choice
模式。我一直试图belongs_to :question, through: :answer
用来执行此操作。
class User
has_many :questions
has_many :choices
end
class Question
belongs_to :user
has_many :answers
has_one :choice, :through => :answer
end
class Answer
belongs_to :question
end
class Choice
belongs_to :user
belongs_to :answer
belongs_to :question, :through => :answer
validates_uniqueness_of :answer_id, :scope => [ :question_id, :user_id ]
end
我正进入(状态
NameError未初始化的常数
User::Choice
当我尝试去做 current_user.choices
如果我不包括
belongs_to :question, :through => :answer
但我想使用它,因为我希望能够 validates_uniqueness_of
我可能忽略了一些简单的事情。任何帮助,将不胜感激。