【发布时间】:2016-10-24 14:27:40
【问题描述】:
我有用户模型,并且(教师、学生和原则)使用 STI 从它继承
每个班级只有很多学生和一位老师。 每个学生都有很多课。 每个班级都有很多学生
class Class < ApplicationRecord
has_and_belongs_to_many:students
belongs_to:teacher
has_many:periods
end
class User < ApplicationRecord
has_and_belongs_to_many:students
belongs_to:teacher
has_many:periods
end
class Teacher < User
has_many:classes
end
class Student < User
has_and_belongs_to_many:classes
has_many:period
end
class Period < ApplicationRecord
belongs_to:teacher
belongs_to:student
end
每节课都有很多节。
我如何设置班级出勤率,因为每个时期都有每个学生的出勤率? 我如何在用户和班级以及期间和出勤之间建立关系?
class Attendance < ApplicationRecord
????????
end
【问题讨论】:
-
您的问题需要重新格式化。你想要什么并不完全清楚。
标签: sql ruby-on-rails rails-models