class EcGraduationSubitem < ApplicationRecord

  default_scope { order(position: :asc) }

  belongs_to :ec_graduation_requirement

  has_many :ec_require_sub_vs_standards, dependent: :destroy
  has_many :ec_course_supports, dependent: :destroy
  has_many :ec_courses, through: :ec_course_supports

  has_many :ec_graduation_subitem_course_targets, dependent: :delete_all
  has_many :ec_course_targets, through: :ec_graduation_subitem_course_targets

  validates :position, presence: true, numericality: { only_integer: true, greater_than: 0 }
  validates :content, presence: true

  accepts_nested_attributes_for :ec_course_supports, allow_destroy: true
end