I have the following method in my concern
:
def all_calculated_stats(sport, group = false)
calculated_stats = Stat.calculated(sport.id, id)
calculated_stats = calculated_stats.group_by { |stat| stat.stat_type.stat_type_category.name } if group
return calculated_stats
end
calculated scope:
scope :calculated, ->(sport_id, athlete_id) { joins(:stat_type => :stat_type_category).where('stat_types.calculated = ? AND stat_type_categories.sport_id = ? AND stats.athlete_id = ?', true, sport_id, athlete_id) }
When the group_by
is ran multiple select statements run to obviously group the objects together, is there anyway to avoid doing this while still grouping the objects?