Shifts are destroyed when a booths is unassigned. An alert appears if there are shifts, but it doesn't if there aren't.
This commit is contained in:
@@ -3,23 +3,26 @@ class Poll
|
||||
belongs_to :booth
|
||||
belongs_to :poll
|
||||
|
||||
before_destroy :destroy_poll_shifts, only: :destroy
|
||||
|
||||
has_many :officer_assignments, class_name: "Poll::OfficerAssignment", dependent: :destroy
|
||||
has_many :officers, through: :officer_assignments
|
||||
has_many :voters
|
||||
has_many :partial_results
|
||||
has_many :recounts
|
||||
|
||||
before_destroy :destroy_poll_shifts
|
||||
|
||||
def has_shifts?
|
||||
|
||||
def shifts?
|
||||
shifts.empty? ? false : true
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def shifts
|
||||
Poll::Shift.where(booth_id: booth_id, officer_id: officer_assignments.pluck(:officer_id), date: officer_assignments.pluck(:date))
|
||||
end
|
||||
|
||||
def destroy_poll_shifts
|
||||
# officers = poll.officers_in_booth(booth.id)
|
||||
# Poll::Shift.where(officer_id: officers, booth_id: booth.id)
|
||||
shifts.destroy_all
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user