0

教師が自分の可用性を設定している間、ここで関連付けを設定することに問題があります。教師は、自分が登録しているコースに対してのみ空き状況を設定できます。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
4

1 に答える 1