diff --git a/app/controllers/contexts_controller.rb b/app/controllers/contexts_controller.rb index b6e4f6b9..45959d51 100644 --- a/app/controllers/contexts_controller.rb +++ b/app/controllers/contexts_controller.rb @@ -39,8 +39,8 @@ class ContextsController < ApplicationController unless @context.nil? @max_completed = current_user.prefs.show_number_completed - @done = @context.todos.completed.limit(@max_completed).reorder("todos.completed_at DESC, todos.created_at DESC").includes(Todo::DEFAULT_INCLUDES) - @not_done_todos = @context.todos.active_or_hidden.not_project_hidden.reorder('todos.due IS NULL, todos.due ASC, todos.created_at ASC').includes(Todo::DEFAULT_INCLUDES) + @done = @context.todos.completed.limit(@max_completed).reorder(Arel.sql("todos.completed_at DESC, todos.created_at DESC")).includes(Todo::DEFAULT_INCLUDES) + @not_done_todos = @context.todos.active_or_hidden.not_project_hidden.reorder(Arel.sql('todos.due IS NULL, todos.due ASC, todos.created_at ASC')).includes(Todo::DEFAULT_INCLUDES) @todos_without_project = @not_done_todos.select{|t| t.project.nil?} @deferred_todos = @context.todos.deferred.includes(Todo::DEFAULT_INCLUDES) diff --git a/app/controllers/todos_controller.rb b/app/controllers/todos_controller.rb index 21f4da8c..eb7be53d 100644 --- a/app/controllers/todos_controller.rb +++ b/app/controllers/todos_controller.rb @@ -629,19 +629,19 @@ class TodosController < ApplicationController @not_done_todos = todos_with_tag_ids. active.not_hidden. - reorder('todos.due IS NULL, todos.due ASC, todos.created_at ASC'). + reorder(Arel.sql('todos.due IS NULL, todos.due ASC, todos.created_at ASC')). includes(Todo::DEFAULT_INCLUDES) @hidden_todos = todos_with_tag_ids. hidden. - reorder('todos.completed_at DESC, todos.created_at DESC'). + reorder(Arel.sql('todos.completed_at DESC, todos.created_at DESC')). includes(Todo::DEFAULT_INCLUDES) @deferred_todos = todos_with_tag_ids. deferred. - reorder('todos.show_from ASC, todos.created_at DESC'). + reorder(Arel.sql('todos.show_from ASC, todos.created_at DESC')). includes(Todo::DEFAULT_INCLUDES) @pending_todos = todos_with_tag_ids. blocked. - reorder('todos.show_from ASC, todos.created_at DESC'). + reorder(Arel.sql('todos.show_from ASC, todos.created_at DESC')). includes(Todo::DEFAULT_INCLUDES) @todos_without_project = @not_done_todos.select{|t| t.project.nil?} @@ -1323,7 +1323,7 @@ end end not_done_todos = not_done_todos. - reorder("todos.due IS NULL, todos.due ASC, todos.created_at ASC"). + reorder(Arel.sql("todos.due IS NULL, todos.due ASC, todos.created_at ASC")). includes(Todo::DEFAULT_INCLUDES) not_done_todos = not_done_todos.limit(sanitize(params[:limit])) if params[:limit] diff --git a/app/models/context.rb b/app/models/context.rb index d8c9fb8d..f9331fcb 100644 --- a/app/models/context.rb +++ b/app/models/context.rb @@ -1,6 +1,6 @@ class Context < ApplicationRecord - has_many :todos, -> { order("todos.due IS NULL, todos.due ASC, todos.created_at ASC").includes(:project) }, :dependent => :delete_all + has_many :todos, -> { order(Arel.sql("todos.due IS NULL, todos.due ASC, todos.created_at ASC")).includes(:project) }, :dependent => :delete_all has_many :recurring_todos, :dependent => :delete_all belongs_to :user diff --git a/app/models/project.rb b/app/models/project.rb index 0b053536..091827f4 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1,5 +1,5 @@ class Project < ApplicationRecord - has_many :todos, -> {order("todos.due IS NULL, todos.due ASC, todos.created_at ASC")}, dependent: :delete_all + has_many :todos, -> {order(Arel.sql("todos.due IS NULL, todos.due ASC, todos.created_at ASC"))}, dependent: :delete_all has_many :notes, -> {order "created_at DESC"}, dependent: :delete_all has_many :recurring_todos diff --git a/app/models/search/search_results.rb b/app/models/search/search_results.rb index 692d0fd0..36130db3 100644 --- a/app/models/search/search_results.rb +++ b/app/models/search/search_results.rb @@ -29,7 +29,7 @@ module Search @user.todos. where("(todos.description LIKE ? OR todos.notes LIKE ?) AND todos.completed_at IS NULL", terms, terms). includes(Todo::DEFAULT_INCLUDES). - reorder("todos.due IS NULL, todos.due ASC, todos.created_at ASC") + reorder(Arel.sql("todos.due IS NULL, todos.due ASC, todos.created_at ASC")) end def complete_todos(terms)