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

rename order_statements to order_statement swithcing it to return single statement

Ivan Kuchin86ab142d89c5
diff --git a/app/models/custom_field/order_statements.rb b/app/models/custom_field/order_statements.rb
index 98c46c8c816..79b773ec7db 100644
--- a/app/models/custom_field/order_statements.rb
+++ b/app/models/custom_field/order_statements.rb
@@ -30,21 +30,21 @@ module CustomField::OrderStatements
# Returns a ORDER BY clause that can used to sort customized
# objects by their value of the custom field.
# Returns false, if the custom field can not be used for sorting.
- def order_statements
+ def order_statement
case field_format
when "list"
- [order_by_list_sql]
+ order_by_list_sql
when "string", "date", "bool", "link"
- [coalesce_select_custom_value_as_string]
+ coalesce_select_custom_value_as_string
when "int", "float"
# Make the database cast values into numeric
# Postgresql will raise an error if a value can not be casted!
# CustomValue validations should ensure that it doesn't occur
- [select_custom_value_as_decimal]
+ select_custom_value_as_decimal
when "user"
- [order_by_user_sql]
+ order_by_user_sql
when "version"
- [order_by_version_sql]
+ order_by_version_sql
end
end
@@ -61,7 +61,7 @@ module CustomField::OrderStatements
# which differ for multi-value select fields,
# because in this case we do want the primary CV values
def group_by_statement
- return order_statements unless field_format == "list"
+ return order_statement unless field_format == "list"
if multi_value?
# We want to return the internal IDs in the case of grouping
diff --git a/app/models/queries/projects/orders/custom_field_order.rb b/app/models/queries/projects/orders/custom_field_order.rb
index 30aa9e3b455..d9ca8de9d1c 100644
--- a/app/models/queries/projects/orders/custom_field_order.rb
+++ b/app/models/queries/projects/orders/custom_field_order.rb
@@ -58,9 +58,7 @@ class Queries::Projects::Orders::CustomFieldOrder < Queries::Orders::Base
private
def order(scope)
- joined_statement = custom_field.order_statements.map do |statement|
- Arel.sql("#{statement} #{direction}")
- end
+ joined_statement = Arel.sql("#{custom_field.order_statement} #{direction}")
scope.order(joined_statement)
end
diff --git a/app/models/queries/work_packages/selects/custom_field_select.rb b/app/models/queries/work_packages/selects/custom_field_select.rb
index 38e429839ad..e4b09ad81b9 100644
--- a/app/models/queries/work_packages/selects/custom_field_select.rb
+++ b/app/models/queries/work_packages/selects/custom_field_select.rb
@@ -33,7 +33,7 @@ class Queries::WorkPackages::Selects::CustomFieldSelect < Queries::WorkPackages:
@cf = custom_field
@name = custom_field.column_name.to_sym
- @sortable = custom_field.order_statements || false
+ @sortable = custom_field.order_statement || false
@groupable = groupable_custom_field?(custom_field) ? custom_field.group_by_statement || false : false
@summable = summable_statement
end
diff --git a/app/models/query/results.rb b/app/models/query/results.rb
index dbf58dcbfa8..51a09954580 100644
--- a/app/models/query/results.rb
+++ b/app/models/query/results.rb
@@ -195,10 +195,8 @@ class Query::Results
##
# Return the case insensitive version for columns with a string type
def case_insensitive_condition(column_key, condition, columns_hash)
- if columns_hash[column_key]&.type == :string
+ if columns_hash[column_key]&.type == :string || custom_field_type(column_key) == "string"
"LOWER(#{condition})"
- elsif custom_field_type(column_key) == "string"
- condition.map { |c| "LOWER(#{c})" }
else
condition
end