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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
extract common sql into method
ulferts0e4ce2f829da
diff --git a/app/models/custom_field/order_statements.rb b/app/models/custom_field/order_statements.rbindex 628bf1f93f3..24694a267a5 100644--- a/app/models/custom_field/order_statements.rb+++ b/app/models/custom_field/order_statements.rb@@ -90,7 +90,7 @@ module CustomField::OrderStatements# COALESCE is here to make sure that blank and NULL values are sorted equally[<<-SQL- COALESCE(#{select_custom_value_as_string}, '')+ COALESCE(#{select_custom_value_as_string}, '')SQL]end@@ -98,9 +98,8 @@ module CustomField::OrderStatementsdef select_custom_value_as_string<<-SQL(SELECT cv_sort.value FROM #{CustomValue.table_name} cv_sort- WHERE cv_sort.customized_type='#{self.class.customized_class.name}'- AND cv_sort.customized_id=#{self.class.customized_class.table_name}.id- AND cv_sort.custom_field_id=#{id} LIMIT 1)+ WHERE #{cv_sort_only_custom_field_condition_sql}+ LIMIT 1)SQLend@@ -109,9 +108,7 @@ module CustomField::OrderStatements(SELECT co_sort.position FROM #{CustomOption.table_name} co_sortLEFT JOIN #{CustomValue.table_name} cv_sortON co_sort.id = CAST(cv_sort.value AS decimal(60,3))- WHERE cv_sort.customized_type='#{self.class.customized_class.name}'- AND cv_sort.customized_id=#{self.class.customized_class.table_name}.id- AND cv_sort.custom_field_id=#{id}+ WHERE #{cv_sort_only_custom_field_condition_sql}LIMIT 1)SQL@@ -120,9 +117,7 @@ module CustomField::OrderStatementsdef select_custom_values_as_group<<-SQLCOALESCE((SELECT string_agg(cv_sort.value, '.') FROM #{CustomValue.table_name} cv_sort- WHERE cv_sort.customized_type='#{self.class.customized_class.name}'- AND cv_sort.customized_id=#{self.class.customized_class.table_name}.id- AND cv_sort.custom_field_id=#{id}+ WHERE #{cv_sort_only_custom_field_condition_sql}AND cv_sort.value IS NOT NULL), '')SQLend@@ -132,18 +127,14 @@ module CustomField::OrderStatementsCOALESCE((SELECT string_agg(co_sort.value, '.' ORDER BY co_sort.position ASC) FROM #{CustomOption.table_name} co_sortLEFT JOIN #{CustomValue.table_name} cv_sortON cv_sort.value IS NOT NULL AND co_sort.id = cv_sort.value::numeric- WHERE cv_sort.customized_type='#{self.class.customized_class.name}'- AND cv_sort.customized_id=#{self.class.customized_class.table_name}.id- AND cv_sort.custom_field_id=#{id}), '')+ WHERE #{cv_sort_only_custom_field_condition_sql}), '')SQLenddef select_custom_value_as_decimal<<-SQL(SELECT CAST(cv_sort.value AS decimal(60,3)) FROM #{CustomValue.table_name} cv_sort- WHERE cv_sort.customized_type='#{self.class.customized_class.name}'- AND cv_sort.customized_id=#{self.class.customized_class.table_name}.id- AND cv_sort.custom_field_id=#{id}+ WHERE #{cv_sort_only_custom_field_condition_sql}AND cv_sort.value <> ''AND cv_sort.value IS NOT NULLLIMIT 1)@@ -165,4 +156,14 @@ module CustomField::OrderStatementsLIMIT 1)SQLend++ private++ def cv_sort_only_custom_field_condition_sql+ <<-SQL+ cv_sort.customized_type='#{self.class.customized_class.name}'+ AND cv_sort.customized_id=#{self.class.customized_class.table_name}.id+ AND cv_sort.custom_field_id=#{id}+ SQL+ endend