[BRIEF DESCRIPTION OF THE SLACK AND ITS PURPOSE]
The current admins are:
- [NAMES]
class Ahoy::Event < ApplicationRecord | |
scope :with_label_grouped_data , -> { | |
# Build a subquery SQL | |
subquery = self.unscoped.select("(case when #{table_name}.properties->>'label' is not NULL then #{table_name}.properties->>'label' else #{table_name}.name end) as label, #{table_name}.id").to_sql | |
# join the subquery to base model and returns the grouped data as Hash | |
self | |
.joins("INNER JOIN (#{subquery}) as labelled_events ON labelled_events.id = #{table_name}.id") | |
.group(:label) |