Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

ensure group_by_join_statement is nil when group_by_statement is nil

Ivan Kuchin76e4096a81f7
diff --git a/app/models/custom_field/order_statements.rb b/app/models/custom_field/order_statements.rb
index 4f93dc33893..20f691f2fcb 100644
--- a/app/models/custom_field/order_statements.rb
+++ b/app/models/custom_field/order_statements.rb
@@ -67,7 +67,7 @@ module CustomField::OrderStatements
# Returns the expression to use in GROUP BY (and ORDER BY) clause to group
# objects by their value of the custom field.
def group_by_statement
- return unless field_format.in?(%w[list date bool int float string link])
+ return unless can_be_used_for_grouping?
order_statement
end
@@ -75,6 +75,8 @@ module CustomField::OrderStatements
# Returns the join statement that is required to group objects by their value
# of the custom field.
def group_by_join_statement
+ return unless can_be_used_for_grouping?
+
return join_for_group_by_list_sql if field_format == "list"
order_join_statement
@@ -82,6 +84,8 @@ module CustomField::OrderStatements
private
+ def can_be_used_for_grouping? = field_format.in?(%w[list date bool int float string link])
+
def join_for_order_sql(value:, join: nil, multi_value: false)
<<-SQL.squish
LEFT OUTER JOIN (