group_assignment_common.rb 1.71 KB
Newer Older
1
2
3
4
5
6
7
module GroupAssignmentCommon
  extend ActiveSupport::Concern

  included do
    include GroupAssignmentAndAssignmentCommon
    include ImportRelation

8
    belongs_to :group_offer, -> { with_deleted } # include imported deleted group offers
9
    has_many :reminder_mailing_volunteers, as: :reminder_mailable, dependent: :destroy
10

11
    has_many :semester_feedbacks, dependent: :destroy
12
13
14
15
    has_many :semester_process_volunteer_missions, dependent: :destroy
    has_many :semester_process_volunteers, through: :semester_process_volunteer_missions
    has_many :semester_processes, through: :semester_process_volunteers

16
    has_one :group_offer_category, through: :group_offer
17
    has_one :creator, -> { with_deleted }, through: :group_offer
18

19
20
    has_one :department, through: :group_offer

21
    # termination record relations
22
23
    belongs_to :period_end_set_by, -> { with_deleted }, class_name: 'User', optional: true,
      inverse_of: 'group_offer_period_ends_set'
24
25
    belongs_to :termination_submitted_by, -> { with_deleted }, class_name: 'User', optional: true,
      inverse_of: 'group_assignment_terminations_submitted', foreign_key: 'termination_submitted_by_id'
26
27
    belongs_to :termination_verified_by, -> { with_deleted }, class_name: 'User', optional: true,
      inverse_of: 'group_offer_terminations_verified'
28
29
    belongs_to :submitted_by, -> { with_deleted }, class_name: 'User',
      inverse_of: 'group_assignments_submitted', foreign_key: 'submitted_by_id', optional: true
30

31
32
33
34
35
36
37
38
39
40
41
42
43
    def to_label
      label_parts.compact.join(' - ')
    end

    def label_parts
      @label_parts ||= [
        'Gruppenangebot',
        group_offer.title,
        group_offer.department.present? && group_offer.department.contact.last_name
      ]
    end
  end
end