semester_feedback.rb 906 Bytes
Newer Older
1
2
3
4
5
6
7
class SemesterFeedback < ApplicationRecord
  belongs_to :author, -> { with_deleted }, class_name: 'User', inverse_of: 'semester_feedbacks'
  belongs_to :semester_process_volunteer
  has_one :semester_process, through: :semester_process_volunteer
  has_one :volunteer, through: :semester_process_volunteer

  # relates to either Assignment or GroupAssignment (not GroupOffer!)
8
9
10
11
12
  belongs_to :assignment, optional: true
  belongs_to :group_assignment, optional: true

  validate :validate_group_assignment_or_assignment_present

Kaspar Vollenweider's avatar
Kaspar Vollenweider committed
13
14
15
16
17
18
19
20
  def mission=(mission)
    if mission.class.name == 'Assignment'
      self.assignment = mission
    else
      self.group_assignment = mission
    end
  end

21
22
23
24
25
26
27
28
29
  def mission
    group_assignment || assignment
  end

  private

  def validate_group_assignment_or_assignment_present
    errors.add(:association_insuficient) if assignment.blank? && group_assignment.blank?
  end
30
end