Files
nairobi/app/models/poll/booth.rb
Senén Rodero Rodríguez 596ef8d1ed Fix queries and scopes after column deletion
Some queries were accessing original column instead of the new
translatable one. This should have been causing unexpected behavior
for requests maded in a different locale than the application default.
2019-04-17 17:40:55 +02:00

23 lines
613 B
Ruby

class Poll
class Booth < ActiveRecord::Base
has_many :booth_assignments, class_name: "Poll::BoothAssignment"
has_many :polls, through: :booth_assignments
has_many :shifts
validates :name, presence: true, uniqueness: true
def self.search(terms)
return Booth.none if terms.blank?
Booth.where("name ILIKE ? OR location ILIKE ?", "%#{terms}%", "%#{terms}%")
end
def self.available
where(polls: { id: Poll.current_or_recounting }).joins(polls: :translations)
end
def assignment_on_poll(poll)
booth_assignments.where(poll: poll).first
end
end
end