Skip to content

Commit

Permalink
remove duplication in list custom field ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
toy committed Sep 19, 2024
1 parent c108939 commit 8b910da
Showing 1 changed file with 10 additions and 22 deletions.
32 changes: 10 additions & 22 deletions app/models/custom_field/order_statements.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,28 +89,16 @@ def select_custom_value_as_string
end

def select_custom_option_position
if multi_value?
<<-SQL.squish
(
SELECT array_agg(co_sort.position ORDER BY co_sort.position)
FROM #{CustomOption.quoted_table_name} co_sort
LEFT JOIN #{CustomValue.quoted_table_name} cv_sort
ON cv_sort.value IS NOT NULL AND co_sort.id = cv_sort.value::bigint
WHERE #{cv_sort_only_custom_field_condition_sql}
)
SQL
else
<<-SQL.squish
(
SELECT co_sort.position
FROM #{CustomOption.quoted_table_name} co_sort
LEFT JOIN #{CustomValue.quoted_table_name} cv_sort
ON cv_sort.value IS NOT NULL AND co_sort.id = cv_sort.value::bigint
WHERE #{cv_sort_only_custom_field_condition_sql}
LIMIT 1
)
SQL
end
<<-SQL.squish
(
SELECT #{multi_value? ? 'array_agg(co_sort.position ORDER BY co_sort.position)' : 'co_sort.position'}
FROM #{CustomOption.quoted_table_name} co_sort
LEFT JOIN #{CustomValue.quoted_table_name} cv_sort
ON cv_sort.value IS NOT NULL AND co_sort.id = cv_sort.value::bigint
WHERE #{cv_sort_only_custom_field_condition_sql}
#{multi_value? ? '' : 'LIMIT 1'}
)
SQL
end

def select_custom_values_as_group
Expand Down

0 comments on commit 8b910da

Please sign in to comment.