I have issue with setting association here while a Teacher sets his/her availability. A teacher can only set availability against the courses he/she is registered for. List of Courses in pre-defined from CourseType table.
At time of teacher registration, user need to select the courses a teacher can teach.
So For teacher while setting availability, only those courses should be visible.
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