From fc5ff61365c0ae78d98c5e2dd6a612a1fbea032a Mon Sep 17 00:00:00 2001 From: Bertocq Date: Tue, 3 Oct 2017 12:30:42 +0200 Subject: [PATCH] Destroy all related OfficerAssignments when destroying a Shift --- app/models/poll/shift.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/models/poll/shift.rb b/app/models/poll/shift.rb index 2870709d7..4edeb26ef 100644 --- a/app/models/poll/shift.rb +++ b/app/models/poll/shift.rb @@ -12,6 +12,7 @@ class Poll before_create :persist_data after_create :create_officer_assignments + before_destroy :destroy_officer_assignments def persist_data self.officer_name = officer.name @@ -29,5 +30,12 @@ class Poll Poll::OfficerAssignment.create!(attrs) end end + + def destroy_officer_assignments + Poll::OfficerAssignment.where(booth_assignment: booth.booth_assignments, + officer: officer, + date: date, + final: recount_scrutiny?).destroy_all + end end end