考虑到以下关联,我需要引用Choice
模型中连接到的Question
.我一直在try 使用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
分
我可能忽略了一些简单的事情.任何帮助都将不胜感激.