course.rb 548 B

1234567891011121314151617181920212223
  1. class Course < ApplicationRecord
  2. belongs_to :school
  3. validates :school_id, presence: true
  4. validates :name, presence: true, length: { maximum: 255 }
  5. validates :starts_on, presence: true
  6. validates :ends_on, presence: true
  7. validate :date_order
  8. has_many :course_participations, dependent: :destroy
  9. has_many :users, through: :course_participations
  10. has_many :lectures
  11. has_many :assignments
  12. private
  13. def date_order
  14. if ends_on < starts_on
  15. errors.add(:ends_on, "should come after starts_on")
  16. end
  17. end
  18. end