#760 ✓resolved
Jeremy Nicoll

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

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.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Referenced by

Pages