#1312 ✓not-applicable

Model.count doesn't properly use SQL "count()" method in 1.0

Reported by jbwiv | June 9th, 2010 @ 09:11 PM

To reproduce, try this:

class Thing

include DataMapper::Resource
property :id, Serial
property :something, Boolean, :default=>false


>> Song.count ~ (0.000296) SELECT "id", "something" FROM "things" ORDER BY "id"

I'd expect that to read:
>> Song.count ~ (0.000296) SELECT count("id") FROM "songs" ORDER BY "id"

Or something similar.

Comments and changes to this ticket

  • Piotr Solnica (solnic)

    Piotr Solnica (solnic) June 10th, 2010 @ 03:04 AM

    • State changed from “new” to “not-applicable”

    You need dm-aggregates gem to do the real count. I just checked it and it works fine.

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) June 11th, 2010 @ 01:14 AM

    @jbwiv: What you were likely using was Enumerable#count, since models are Enumerable. As solnic mentioned you need dm-aggregates to use an optimized count (along with other aggregate methods like sum, min, max, avg, etc).

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 »