course.rb 521 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
7
  has_many :course_sections
Zac Wood's avatar
Zac Wood committed
8

9
  # Ensure all necessary are fields present.
Zac Wood's avatar
Zac Wood committed
10
11
12
13
  validates :course_number, presence: true
  validates :subject, presence: true
  validates :semester_id, presence: true

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