Commit 5a4ac5f6 authored by Alan Paruszewski's avatar Alan Paruszewski

Fix problem with sorting in GraphQL by case expression

parent 79d0b30e
......@@ -103,8 +103,8 @@ module EE
scope :order_title_desc, -> { reorder(title: :desc, id: :desc) }
scope :order_created_at_asc, -> { reorder(created_at: :asc, id: :desc) }
scope :order_created_at_desc, -> { reorder(created_at: :desc, id: :desc) }
scope :order_report_type_asc, -> { reorder(report_type_order.asc, id: :desc) }
scope :order_report_type_desc, -> { reorder(report_type_order.desc, id: :desc) }
scope :order_report_type_asc, -> { select(*arel.projections, report_type_order.as('case_order_value')).reorder(report_type_order.asc, id: :desc) }
scope :order_report_type_desc, -> { select(*arel.projections, report_type_order.as('case_order_value')).reorder(report_type_order.desc, id: :desc) }
scope :order_id_desc, -> { reorder(id: :desc) }
scope :with_limit, -> (maximum) { limit(maximum) }
......
......@@ -95,7 +95,7 @@ module Gitlab
elsif ordering_by_similarity?(order_value)
['similarity', order_value.direction, order_value.expr]
elsif ordering_by_case?(order_value)
[order_value.expr.case.name.to_s, order_value.direction, order_value.expr]
['case_order_value', order_value.direction, order_value.expr]
else
[order_value.expr.name, order_value.direction, nil]
end
......
......@@ -69,7 +69,7 @@ RSpec.describe Gitlab::Graphql::Pagination::Keyset::OrderInfo do
it 'assigns the right attribute name, named function, and direction' do
expect(order_list.count).to eq 1
expect(order_list.first.attribute_name).to eq 'pending_delete'
expect(order_list.first.attribute_name).to eq 'case_order_value'
expect(order_list.first.named_function).to be_kind_of(Arel::Nodes::Case)
expect(order_list.first.sort_direction).to eq :asc
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment