course.rb 493 Bytes
Newer Older
Zac Wood's avatar
Zac Wood committed
1 2 3
# Contains logic regarding the +Course+ model.
#
# TODO: Add more docs
Zac Wood's avatar
Zac Wood committed
4
class Course < ApplicationRecord
Zac Wood's avatar
Zac Wood committed
5
  # Each course belongs to a +Semester+
Zac Wood's avatar
Zac Wood committed
6
  belongs_to :semester
Zac Wood's avatar
Zac Wood committed
7 8 9 10 11 12

  # Ensure all necessary fields are present.
  validates :course_number, presence: true
  validates :subject, presence: true
  validates :semester_id, presence: true

Zac Wood's avatar
Zac Wood committed
13
  # Returns all +CourseSection+ objects that belong to this course.
14
  # @return [Array]
Zac Wood's avatar
Zac Wood committed
15 16
  def course_sections
    CourseSection.where course_id: id
Zac Wood's avatar
Zac Wood committed
17
  end
Zac Wood's avatar
Zac Wood committed
18
end