我认为所缺少的只是一个Answer
模型,它与用户相关联。
或者,您也可以在“父母”上定义关系Question
。
class Grade < ActiveRecord::Base
has_many :users, :through => :sections # optional. i.e. 'users that have answers in this grade'
end
class Section < ActiveRecord::Base
has_many :users, :through => :exercises # optional
end
class Exercise < ActiveRecord::Base
has_many :users, :through => :questions # optional
end
class Question < ActiveRecord::Base
has_many :answers
has_many :users, :through => :answers # optional
end
class Answer < ActiveRecord::Base
belongs_to :question
belongs_to :user
end
class User < ActiveRecord::Base
has_many :answers
end
更新:重新阅读您的描述,我认为CorrectAnswer
会比Answer
.