鑑於以下關聯,我需要引用Question
Choice
連接從Choice
模型。我一直在嘗試使用belongs_to :question, through: :answer
來執行此操作。belongs_to通過協會
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
我可能忽略了一些簡單的東西。任何幫助,將不勝感激。
也許是值得改變的接受答案給代表嗎? – 23inhouse 2016-06-07 09:11:52