Browse Source

Clear SG of participant if not attending

Maarten van den Berg 7 years ago
parent
commit
42121901c7
1 changed files with 7 additions and 0 deletions
  1. 7 0
      app/models/participant.rb

+ 7 - 0
app/models/participant.rb

19
   belongs_to :activity
19
   belongs_to :activity
20
   belongs_to :subgroup, optional: true
20
   belongs_to :subgroup, optional: true
21
 
21
 
22
+  after_validation :clear_subgroup, if: 'self.attending != true'
23
+
22
   validates :person_id,
24
   validates :person_id,
23
     uniqueness: {
25
     uniqueness: {
24
       scope: :activity_id,
26
       scope: :activity_id,
76
     ParticipantMailer.subgroup_notification(self.person, self.activity, self).deliver_later
78
     ParticipantMailer.subgroup_notification(self.person, self.activity, self).deliver_later
77
   end
79
   end
78
 
80
 
81
+  # Clear subgroup if person is set to 'not attending'.
82
+  def clear_subgroup
83
+    self.subgroup = nil
84
+  end
85
+
79
 end
86
 end