我有以下方法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
计算范围:
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) }
当group_by
运行多个选择语句以将对象明显地组合在一起时,是否有办法在仍然对对象进行分组的同时避免这样做?