Class: AhoyCaptain::EntryPagesQuery

Inherits:
ApplicationQuery show all
Defined in:
app/queries/ahoy_captain/entry_pages_query.rb

Instance Attribute Summary

Attributes inherited from ApplicationQuery

#params

Instance Method Summary collapse

Methods inherited from ApplicationQuery

call, inherited, #initialize, #inspect

Constructor Details

This class inherits a constructor from AhoyCaptain::ApplicationQuery

Instance Method Details

#buildObject



4
5
6
7
8
9
10
11
12
13
14
# File 'app/queries/ahoy_captain/entry_pages_query.rb', line 4

def build
  max_id_query = event_query.with_routes.select("min(#{AhoyCaptain.event.table_name}.id) as id").group("visit_id")
  event_query.with_routes.select(
    "#{AhoyCaptain.config.event[:url_column]} as url",
    "count(#{AhoyCaptain.config.event[:url_column]}) as count",
    "sum(count(#{AhoyCaptain.config.event[:url_column]})) over() as total_count"
  )
                 .where(id: max_id_query)
                 .group(AhoyCaptain.config.event[:url_column])
                 .order(Arel.sql "count(#{AhoyCaptain.config.event[:url_column]}) desc")
end