#884 ✓not-applicable
Nick Plante

[PATCH] dm-aggregates count is incorrect when :fields are specified

Reported by Nick Plante | June 4th, 2009 @ 10:04 PM

Value returned by count is incorrect when the :fields option is used (would make sense in conjunction with :unique for instance). Here's an example use case:


I wrote a spec and have provided a patch for this against 0.9.12. I'll send a pull request too.


Comments and changes to this ticket

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) June 5th, 2009 @ 04:21 AM

    Why not just use the documented API for specifying the fields, eg:

    Project.count(:name, :owner)

    The Model.count method wasn't built to receive :fields, and afaik there's no docs or specs showing it as an example.

    With that said, I'm just trying to understand if there will be any cases that allowing :fields will provide that can't be met with the existing API. Can you think of any?

  • Nick Plante

    Nick Plante June 5th, 2009 @ 08:41 AM

    I should have been more thorough in my ticket; the issue originally occurred when using dm-is-paginated, which passes through to #count to calculate the number of pages. Here's the original query:

    @pages, @projects = Project.paginated(:order => [:created_at.desc],
                                          :fields => [:owner, :name],
                                          :unique => true,
                                          :per_page =>10,
                                          :page => (params[:page] || 1).to_i)

    This use of paginated would end up passing the :fields option through to count to calculate the number of pages, but since it gets ignored / overwritten, the page count returned does not reflect the unique constraint on the named fields.

  • Nick Plante

    Nick Plante June 5th, 2009 @ 08:55 AM

    Another solution would have been to patch dm-is-paginated so that paginated detects :fields and passes them "the right way" but I figured that it would make the most sense for the standard finder arguments to be supported by #count because this might also be happening other places. Open to suggestions if you don't like my resolution.

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) July 22nd, 2009 @ 03:45 PM

    • State changed from “unconfirmed” to “confirmed”

    FYI: I would accept a patch to dm-aggregates on the "next" branch that accepts :fields as a finder argument.

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) July 22nd, 2009 @ 04:05 PM

    • Assigned user set to “Michael Klishin (antares)”
  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) November 10th, 2009 @ 03:48 PM

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

    A patch would be accepted to add :fields as a finder argument to #count, but since there has been no progress on this ticket and there is a work-around using the standard API I'm going to mark this as closed for now.

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 »