#120 √ invalid
Eric

[PATCH] ActiveRecord calculations only accept one grouping field

Reported by Eric | May 6th, 2008 @ 01:25 AM

This is a patch from trac: http://dev.rubyonrails.org/ticke...

It allows for multiple columns to used in calculation groups.

The patch didn't work with the latest changes on github so I updated it.

Comments and changes to this ticket

  • Eric
  • Pratik

    Pratik May 11th, 2008 @ 09:37 PM

    • → State changed from “new” to “invalid”
    • → Title changed from “[PATCH] ActiveRecord calculations only accept one grouping field” to “ActiveRecord calculations only accept one grouping field”

    I'm not hugely in favor of this patch because,

    a. It's not backward compatible. Well, not for me at least as I'm quite used to abuse :group using it somewhat like :group => "items.user_id HAVING items_count > 5"

    b. It looks quite complex.

    So I'm tempted to say "plugin material".

    However, please send an email to core mailing list and if there's enough interest in the patch, we can get it in.

    Thanks!

  • Eric

    Eric May 20th, 2008 @ 11:28 PM

    So you're mostly looking for someone to add :having to find?

    I found that the way the results were returned (in nested arrays) for the keys that were grouped by ended up not being very natural and so I will be updating the patch to make the grouped by results a simple array.

  • Eric

    Eric May 20th, 2008 @ 11:50 PM

    I just noticed, it looks like ActiveRecord already has support for :having.

    http://github.com/rails/rails/se...

    Is this not what you need?

  • Eric

    Eric May 21st, 2008 @ 01:43 AM

    • → Title changed from “ActiveRecord calculations only accept one grouping field” to “[PATCH] ActiveRecord calculations only accept one grouping field”

    This updated patch causes keys that were grouped by to be part of a single array. So, for instance, the call:

      c = Account.count(1, :group => [:credit_limit, :firm_id])
      c #=> [[[50, nil], 1], [[50, 1], 1], [[50, 6], 1], [[53, 9], 1], [[55, 6], 1], [[60, 2], 1]]
    

    the "50" and "nil" would correspond to the :credit_limit and :firm_id.

  • Eric

    Eric May 21st, 2008 @ 01:56 AM

    I just noticed there was a needless change of how the elements were being added to the ActiveSupport::OrderedHash.

  • Pratik

    Pratik May 21st, 2008 @ 10:17 AM

    Hey Eric,

    My bad. I never knew about :having ! Thanks for the enlightenment :)

    I still feel the patch is a bit too complex and a better fit for a plugin. Why don't you email to core mailing list and find out what everyone else feels ?

    Thanks again!

  • Jeremy Weiskotten

    Jeremy Weiskotten September 5th, 2008 @ 07:19 PM

    • → Tag changed from “” to “activerecord edge patch”

    A plugin is now available at http://github.com/patientslikeme...

Please Login or create a free account to add a new comment.

You can update this ticket by sending an email to from your email client. (help)

Create your profile

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

Source available from github

The Git repository resides at http://github.com/rails

Check out the current development trunk (Edge Rails) with:

git clone git://github.com/rails/rails.git

Creating or reviewing a patch

See the contributor guide.

Creating a feature request

Please don't. If you want a new feature in Rails, you'll have to pull up your sleeves and get busy yourself. Or convince someone else to do it. See the contributor guide on how to get going. But posting them here is just going to lead to ticket root.

Creating a bug report

When creating a bug report, be sure to include as much relevant information as possible. Post the code sample that causes the problem. Preferably, alter the unit tests and show through either changed or added tests how the expected behavior is not occuring.

Security vulnerabilities should be reported via an email to security@rubyonrails.org, do not use trac for reporting security vulnerabilities. All content in trac is publicly available as soon as it is posted.

Then don't get your hopes up. Unless you have a "Code Red, Mission Critical, The World is Coming to an End" kinda bug, you're creating this ticket in the hope that others with the same problem will be able to collaborate with you on solving it. Do not expect that the ticket automatically will see any activity or that others will jump to fix it. Creating a ticket like this is mostly to help yourself start on the path of fixing the problem and for others to sign on to with a "I'm having this problem too".

Shared Ticket Bins

People watching this ticket