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:
Dan Rice 2012-10-04 10:20:26 -04:00
parent 33c3c578f6
commit 5b6cbf566a
2 changed files with 8 additions and 4 deletions

View file

@ -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