Class: Decidim::Votings::Admin::PollingOfficersJoinPollingStations

Inherits:
Query
  • Object
show all
Defined in:
decidim-elections/app/queries/decidim/votings/admin/polling_officers_join_polling_stations.rb

Overview

A class join the polling officers with their respective polling stations.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Query

#cached_query, #each, #eager?, #exists?, merge, #none?, #relation?, #|

Constructor Details

#initialize(polling_officers) ⇒ PollingOfficersJoinPollingStations

Initializes the class.

polling_officers - the collection of polling officers



18
19
20
# File 'decidim-elections/app/queries/decidim/votings/admin/polling_officers_join_polling_stations.rb', line 18

def initialize(polling_officers)
  @polling_officers = polling_officers
end

Class Method Details

.for(polling_officers) ⇒ Object

Syntactic sugar to initialize the class and return the queried objects.

polling_officers - the collection of polling officers



11
12
13
# File 'decidim-elections/app/queries/decidim/votings/admin/polling_officers_join_polling_stations.rb', line 11

def self.for(polling_officers)
  new(polling_officers).query
end

Instance Method Details

#queryObject

Finds joins the polling officers with their associated polling stations.

Returns an ActiveRecord::Relation.



25
26
27
28
29
# File 'decidim-elections/app/queries/decidim/votings/admin/polling_officers_join_polling_stations.rb', line 25

def query
  @polling_officers
    .joins("LEFT JOIN decidim_votings_polling_stations presided_station ON decidim_votings_polling_officers.presided_polling_station_id = presided_station.id
            LEFT JOIN decidim_votings_polling_stations managed_station ON decidim_votings_polling_officers.managed_polling_station_id = managed_station.id")
end