class Discipline::StudentDetention < ApplicationRecord
  include Base::Discipline::StudentDetention

  associations_for legacy: true do |a|
    a.belongs_to :school
    a.belongs_to :student, inverse_of: :discipline_detentions
    a.belongs_to :author, class_name: 'User', primary_key: :UserID,
      inverse_of: :discipline_authored_detentions
    a.belongs_to :monitor, class_name: 'User', primary_key: :UserID,
      inverse_of: :discipline_monitored_detentions, optional: true
  end

  scope :by_student_ids, ->(ids) { where(student_id: ids) if ids.present? }
  scope :by_classroom, ->(classroom) do
    joins(:student).merge(Student.by_classroom(classroom))
  end
end
