Skip to content

A platform for community discussion. Free, open, simple.

FIX: Order result set of category search (#24027)

Bianca Nenciuad433daf3ac4
diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb
index 10baa4cce6d..5d6086d0e41 100644
--- a/app/controllers/categories_controller.rb
+++ b/app/controllers/categories_controller.rb
@@ -352,12 +352,13 @@ class CategoriesController < ApplicationController
categories = categories.order(<<~SQL) if prioritized_category_id.present?
CASE
- WHEN id = #{prioritized_category_id} OR parent_category_id = #{prioritized_category_id} THEN 0
- ELSE 1
+ WHEN id = #{prioritized_category_id} THEN 1
+ WHEN parent_category_id = #{prioritized_category_id} THEN 2
+ ELSE 3
END
SQL
- categories = categories.order(:read_restricted)
+ categories.order(:id)
render json: categories, each_serializer: SiteCategorySerializer
end