Files
grecia/app/models/poll/booth_assignment.rb
Javi Martín 2b4b2f3442 Use aria-label in admin table actions
This way screen reader users will know which record they're going to
access when focusing on a link to a certain action. Otherwise they'd
hear something like "Edit, link", and they wouldn't know which record
they'll end up editing if they follow the link.
2021-09-20 20:27:37 +02:00

35 lines
767 B
Ruby

class Poll
class BoothAssignment < ApplicationRecord
belongs_to :booth
belongs_to :poll
delegate :name, to: :booth
before_destroy :destroy_poll_shifts, only: :destroy
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