Files
nairobi/app/models/poll/booth_assignment.rb
Javi Martín 9c95735534 Remove invalid key in before_destroy
The `only:` key does not apply to model callbacks. It was added in commit 1077e25b2, probably by accident.

Using this key raises an error in Rails 6.0.
2022-03-21 20:43:50 +01:00

35 lines
751 B
Ruby

class Poll
class BoothAssignment < ApplicationRecord
belongs_to :booth
belongs_to :poll
delegate :name, to: :booth
before_destroy :destroy_poll_shifts
has_many :officer_assignments, dependent: :destroy
has_many :officers, through: :officer_assignments
has_many :voters
has_many :partial_results
has_many :recounts
def shifts?
!shifts.empty?
end
def unable_to_destroy?
(partial_results.count + recounts.count).positive?
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
shifts.destroy_all
end
end
end