From 34dfeee9c95656590a73044c75dfdf28e666147c Mon Sep 17 00:00:00 2001 From: kikito Date: Sat, 11 Feb 2017 12:43:05 +0100 Subject: [PATCH] Denormalizes booth_assignmen on the models where it is needed --- app/models/poll/voter.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/poll/voter.rb b/app/models/poll/voter.rb index 0826092d2..da05b1bc6 100644 --- a/app/models/poll/voter.rb +++ b/app/models/poll/voter.rb @@ -16,7 +16,7 @@ class Poll validates :document_number, presence: true, uniqueness: { scope: [:poll_id, :document_type], message: :has_voted } validates :origin, inclusion: { in: VALID_ORIGINS } - before_validation :set_demographic_info, :set_document_info + before_validation :set_demographic_info, :set_document_info, :set_denormalized_booth_assignment_id scope :web, -> { where(origin: "web") } scope :booth, -> { where(origin: "booth") } @@ -38,6 +38,10 @@ class Poll private + def set_denormalized_booth_assignment_id + self.booth_assignment_id ||= officer_assignment.try(:booth_assignment_id) + end + def in_census? census_api_response.valid? end