diff --git a/app/models/report/group_by/base.rb b/app/models/report/group_by/base.rb index 0d90117bd8..c2d7936d54 100644 --- a/app/models/report/group_by/base.rb +++ b/app/models/report/group_by/base.rb @@ -59,8 +59,12 @@ class Report::GroupBy def define_group(sql) fields = all_group_fields - sql.group_by fields - sql.select fields + # fields usually are Strings which we want select and group_by + # sometimes fields are arrays of the form [String,String], where + # the fields.first is to select and where we have to group on field.last + #TODO: differenciate between all_group_fields and all_select_fields + sql.select fields.map {|field| field.is_a?(String) ? field : field.first} + sql.group_by fields.map {|field| field.is_a?(String) ? field : field.last} end end end \ No newline at end of file diff --git a/app/models/report/group_by/singleton_value.rb b/app/models/report/group_by/singleton_value.rb index 197b9fcf80..1fbea71fb9 100644 --- a/app/models/report/group_by/singleton_value.rb +++ b/app/models/report/group_by/singleton_value.rb @@ -2,6 +2,12 @@ class Report::GroupBy class SingletonValue < Base dont_display! + def all_group_fields(prefix = true) + parent_fields = parent.all_group_fields if parent + #TODO: differenciate between all_group_fields and all_select_fields + (parent_fields || []) << ['1 as singleton_value', 'singleton_value'] + end + def define_group(sql) sql.select "1 as singleton_value" sql.group_by "singleton_value"