Skip to content

Commit

Permalink
use group_id instead of id to name the column used to group from summing
Browse files Browse the repository at this point in the history
  • Loading branch information
toy committed Oct 15, 2024
1 parent cb1f5af commit 6efbeb9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:)
Expand Down
9 changes: 5 additions & 4 deletions app/models/query/results/sums.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions modules/costs/spec/lib/costs/query_currency_select_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6efbeb9

Please sign in to comment.