This project is archived and is in readonly mode.

#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 set to activerecord, edge, patch

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

  • Eric

    Eric February 21st, 2009 @ 06:31 AM

    Is there a way to un-mark this as invalid?

  • Eric

    Eric March 5th, 2011 @ 06:17 AM

    • Importance changed from “” to “”

    I wanted to point out it looks like this finally made it into ActiveRecord 3.0.4:
    https://rails.lighthouseapp.com/projects/8994/tickets/497

Create your profile

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

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages