diff --git a/app/controllers/admin/poll/officer_assignments_controller.rb b/app/controllers/admin/poll/officer_assignments_controller.rb index 7532362a7..d46d0418e 100644 --- a/app/controllers/admin/poll/officer_assignments_controller.rb +++ b/app/controllers/admin/poll/officer_assignments_controller.rb @@ -19,7 +19,7 @@ class Admin::Poll::OfficerAssignmentsController < Admin::Poll::BaseController @officer_assignments = ::Poll::OfficerAssignment. joins(:booth_assignment). includes(:recounts, booth_assignment: :booth). - where("officer_id = ? AND poll_booth_assignments.poll_id = ?", @officer.id, @poll.id). + by_officer_and_poll(@officer.id, @poll.id). order(:date) end diff --git a/app/models/poll/officer_assignment.rb b/app/models/poll/officer_assignment.rb index 417e6a150..bdd074995 100644 --- a/app/models/poll/officer_assignment.rb +++ b/app/models/poll/officer_assignment.rb @@ -14,6 +14,9 @@ class Poll scope :voting_days, -> { where(final: false) } scope :final, -> { where(final: true) } + scope :by_officer_and_poll, ->(officer_id, poll_id) do + where("officer_id = ? AND poll_booth_assignments.poll_id = ?", officer_id, poll_id) + end before_create :log_user_data