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 (