当老师设置他/她的可用性时,我在这里设置关联有问题。教师只能针对他/她注册的课程设置可用性。从 CourseType 表中预定义的课程列表。
在教师注册时,用户需要选择教师可以教授的课程。
所以对于教师来说,在设置可用性时,只有那些课程应该是可见的。
class TeacherDetail < UserDetail
include Mongoid::Document
has_one :user, as: :user_type
has_and_belongs_to_many :courses, class_name: "CourseType", inverse_of: :course_type, autosave: true
accepts_nested_attributes_for :user
end
class CourseType
include Mongoid::Document
include Mongoid::Timestamps
field :type, type: String
field :name, type: String
auto_increment :type_id
has_and_belongs_to_many :teacher_details, class_name: "TeacherDetail", inverse_of: :teacher_id, autosave: true
end
class TeacherAvailibility
include Mongoid::Document
include Mongoid::Timestamps
include RailsAdmin::TeacherAvailabilityRailsAdminConcern
field :date, type: Date
field :start_time, type: String
field :end_time, type: String
field :cost, type: Float
belongs_to :teacher_detail
end