принадлежит_ через ассоциации
Учитывая следующие ассоциации, мне нужно сослаться на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
Я, наверное, упускаю из виду что-то простое. Любая помощь будет оценена.