diff --git a/app/models/queries/work_packages/selects/work_package_select.rb b/app/models/queries/work_packages/selects/work_package_select.rb index 90ed98e5f530..9b9603518367 100644 --- a/app/models/queries/work_packages/selects/work_package_select.rb +++ b/app/models/queries/work_packages/selects/work_package_select.rb @@ -47,7 +47,7 @@ def self.select_group_by(group_by_statement) group_by = group_by_statement group_by = group_by.first if group_by.is_a?(Array) - "#{group_by} id" + "#{group_by} group_id" end def self.scoped_column_sum(scope, select, grouped:, query:) diff --git a/app/models/query/results/sums.rb b/app/models/query/results/sums.rb index d349e199f2f9..6da74e8cfba6 100644 --- a/app/models/query/results/sums.rb +++ b/app/models/query/results/sums.rb @@ -43,10 +43,10 @@ def all_group_sums return nil unless query.grouped? sums_by_id = sums_select(true).inject({}) do |result, group_sum| - result[group_sum["id"]] = {} + result[group_sum["group_id"]] = {} query.summed_up_columns.each do |column| - result[group_sum["id"]][column] = group_sum[column.name.to_s] + result[group_sum["group_id"]][column] = group_sum[column.name.to_s] end result @@ -59,7 +59,7 @@ def all_group_sums def sums_select(grouped = false) select = if grouped - ["work_packages.id"] + ["work_packages.group_id"] else [] end @@ -96,7 +96,8 @@ def sums_callable_joins(grouped) callable_summed_up_columns .map do |c| join_condition = if grouped - "#{c.name}.id = work_packages.id OR #{c.name}.id IS NULL AND work_packages.id IS NULL" + "#{c.name}.group_id = work_packages.group_id OR " \ + "#{c.name}.group_id IS NULL AND work_packages.group_id IS NULL" else "TRUE" end diff --git a/modules/costs/spec/lib/costs/query_currency_select_spec.rb b/modules/costs/spec/lib/costs/query_currency_select_spec.rb index 8139e7f1c884..90794f8d2985 100644 --- a/modules/costs/spec/lib/costs/query_currency_select_spec.rb +++ b/modules/costs/spec/lib/costs/query_currency_select_spec.rb @@ -98,7 +98,7 @@ ) expect(ActiveRecord::Base.connection.select_all(instance.summable.(query, true).to_sql).columns) - .to match_array %w(id material_costs) + .to match_array %w(group_id material_costs) end end end @@ -136,7 +136,7 @@ ) expect(ActiveRecord::Base.connection.select_all(instance.summable.(query, true).to_sql).columns) - .to match_array %w(id labor_costs) + .to match_array %w(group_id labor_costs) end end end