mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-16 15:20:13 +01:00
Don't sort todos when counting them
Grouping isn't as lax in PostgreSQL as it is in MySQL or SQLite. All sort fields also need to be in the GROUP BY, or be aggregated. The order isn't relevant when counting, so simply don't order in that case. Fix #1336
This commit is contained in:
parent
33c3c578f6
commit
5b6cbf566a
2 changed files with 8 additions and 4 deletions
|
|
@ -280,14 +280,14 @@ class ApplicationController < ActionController::Base
|
|||
|
||||
def init_not_done_counts(parents = ['project','context'])
|
||||
parents.each do |parent|
|
||||
eval("@#{parent}_not_done_counts ||= current_user.todos.active.group('#{parent}_id').count")
|
||||
eval("@#{parent}_deferred_counts ||= current_user.todos.deferred.group('#{parent}_id').count")
|
||||
eval("@#{parent}_not_done_counts ||= current_user.todos.active.count_by_group('#{parent}_id')")
|
||||
eval("@#{parent}_deferred_counts ||= current_user.todos.deferred.count_by_group('#{parent}_id')")
|
||||
end
|
||||
end
|
||||
|
||||
def init_project_hidden_todo_counts(parents = ['project','context'])
|
||||
parents.each do |parent|
|
||||
eval("@#{parent}_project_hidden_todo_counts = @#{parent}_project_hidden_todo_counts || current_user.todos.count(:conditions => ['state = ? or state = ?', 'project_hidden', 'active'], :group => :#{parent}_id)")
|
||||
eval("@#{parent}_project_hidden_todo_counts ||= current_user.todos.active_or_hidden.count_by_group('#{parent}_id')")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -81,7 +81,11 @@ class User < ActiveRecord::Base
|
|||
end
|
||||
has_many :todos,
|
||||
:order => 'todos.completed_at DESC, todos.created_at DESC',
|
||||
:dependent => :delete_all
|
||||
:dependent => :delete_all do
|
||||
def count_by_group(g)
|
||||
except(:order).group(g).count
|
||||
end
|
||||
end
|
||||
has_many :recurring_todos,
|
||||
:order => 'recurring_todos.completed_at DESC, recurring_todos.created_at DESC',
|
||||
:dependent => :delete_all
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue