7
通过关联归属
考虑下面的协会,我需要引用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未初始化的常数 …