浏览代码

Clear SG of participant if not attending

Maarten van den Berg 7 年之前
父节点
当前提交
42121901c7
共有 1 个文件被更改,包括 7 次插入0 次删除
  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