class EcMajorSchool < ApplicationRecord
  belongs_to :ec_major
  belongs_to :school

  # 专业对应的学年
  has_many :ec_years, dependent: :destroy

  # 学校对应的专业中成员
  has_many :ec_major_school_users, dependent: :destroy
  has_many :users, through: :ec_major_school_users

  scope :is_template, -> { where(template_major: true) }
  scope :not_template, -> { where(template_major: false) }

  delegate :code, :name, to: :ec_major

  # 是否为该专业管理员
  def manager?(user)
    ec_major_school_users.exists?(user_id: user.id)
  end
end
