diff --git a/backend/app/controllers/posts_controller.rb b/backend/app/controllers/posts_controller.rb index aeef248..9a4b9b0 100644 --- a/backend/app/controllers/posts_controller.rb +++ b/backend/app/controllers/posts_controller.rb @@ -65,15 +65,20 @@ class PostsController < ApplicationController end sort_sql = - if order[0] == 'original_created_at' + case order[0] + when 'original_created_at' 'COALESCE(posts.original_created_before - INTERVAL 1 MINUTE,' + 'posts.original_created_from,' + - 'posts.created_at) ' + - order[1] + 'posts.created_at) ' + when 'updated_at' + 'posts.updated_at_all' else - "posts.#{ order[0] } #{ order[1] }" + "posts.#{ order[0] }" end - posts = q.order(Arel.sql("#{ sort_sql }")).limit(limit).offset(offset).to_a + posts = q.order(Arel.sql("#{ sort_sql } #{ order[1] }, id #{ order[1] }")) + .limit(limit) + .offset(offset) + .to_a q = q.except(:select, :order)