Files
nairobi/app/models/poll/booth.rb
Javi Martín 27ed26d6f2 Remove unnecessary class names in relations
Just like we do in the Budget module, and in some places in the Poll and
Legislation modules, we don't need to specify the class name when the
name of the relation matches the name of a class in the same module.
2019-10-25 19:03:14 +02:00

30 lines
643 B
Ruby

class Poll
class Booth < ApplicationRecord
has_many :booth_assignments
has_many :polls, through: :booth_assignments
has_many :shifts
validates :name, presence: true, uniqueness: true
def self.search(terms)
Booth.where("name ILIKE ? OR location ILIKE ?", "%#{terms}%", "%#{terms}%")
end
def self.quick_search(terms)
if terms.blank?
Booth.none
else
search(terms)
end
end
def self.available
where(polls: { id: Poll.current_or_recounting }).joins(:polls)
end
def assignment_on_poll(poll)
booth_assignments.find_by(poll: poll)
end
end
end