
No ordering on aggregates
Reported by Jeremy Nicoll | January 9th, 2009 @ 02:55 PM | in 1.0.0
Slight problem with aggregates. It seems that the ORDER BY clause is put into the SQL query, but it ignores the .desc and .asc calls on the symbol. Ordering is fairly important in dealing with aggregates, I'd assume. Below is code with the SQL query that is generated:
class Klass
include DataMapper::Resource
property id, Serial
property :date, Date
end
Klass.auto_migrate!
Klass.create(:date => Date.today)
Klass.create(:date => Date.today)
Klass.create(:date => Date.today - 1)
Klass.create(:date => Date.today - 1)
Klass.all(:order => [:date.desc]).aggregate(:date, :id.count)
# ~ (0.063324) SELECT `date`, COUNT(`id`) FROM `klasses` GROUP BY `date` ORDER BY `date`
The query that should be generated is SELECT
date
, COUNT(id
) FROM klasses
GROUP BY date
ORDER BY date
DESC
The query above works on MySQL 5. I have not tested it with other DB's.
Comments and changes to this ticket
-
Dan Kubb (dkubb) February 8th, 2009 @ 02:27 PM
- Tag set to dm-aggregates
- Assigned user set to Michael Klishin (antares)
-
Michael Klishin (antares) March 31st, 2009 @ 02:47 PM
- Milestone set to 0.10.0
- State changed from unconfirmed to accepted
-
Michael Klishin (antares) March 31st, 2009 @ 02:48 PM
- State changed from accepted to confirmed
-
Dan Kubb (dkubb) July 22nd, 2009 @ 04:00 PM
- Milestone cleared.
-
Dan Kubb (dkubb) February 5th, 2010 @ 01:46 AM
- State changed from confirmed to accepted
- Assigned user changed from Michael Klishin (antares) to Dan Kubb (dkubb)
- Milestone set to 1.0.0
-
Dan Kubb (dkubb) February 5th, 2010 @ 02:01 AM
- State changed from accepted to resolved
(from [17c0dbe0dfd4f7d8c0d63c349b5f932b62ddd5a7]) Allow collection order to be used if it matches the fields used
[#760 state:resolved] http://github.com/datamapper/dm-more/commit/17c0dbe0dfd4f7d8c0d63c3...
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
People watching this ticket
Tags
Referenced by
-
760 No ordering on aggregates [#760 state:resolved] http://github.com/datamapper/dm-mo...