From 73daf9f9b832b196c0cb920f51f60bdbab381a1d Mon Sep 17 00:00:00 2001 From: Ivan Kuchin Date: Thu, 10 Oct 2024 20:05:38 +0200 Subject: [PATCH] ensure group_by_join_statement is nil when group_by_statement is nil --- app/models/custom_field/order_statements.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/custom_field/order_statements.rb b/app/models/custom_field/order_statements.rb index 3b8fd2322a48..82128074fea8 100644 --- a/app/models/custom_field/order_statements.rb +++ b/app/models/custom_field/order_statements.rb @@ -67,12 +67,14 @@ def order_null_handling(asc) # which differ for multi-value select fields, # because in this case we do want the primary CV values 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 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 @@ -80,6 +82,8 @@ def group_by_join_statement 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 (