0
나는이 내 concern
에서 다음과 같은 방법레일 GROUP_BY 호출
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
여러 선택 문이 오브젝트 함께 분명히 그룹에 실행 실행됩니다 어쨌든 개체를 그룹화하면서이 작업을 수행하지 않도록 할 것입니까?