Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

[PATCH] ActiveRecord calculations only accept one grouping field

#120

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.

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

State: invalid
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Eric
  2. Pratik
    Pratik
    • 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!

    May 11th, 2008 @ 09:37 PM

  3. Eric
    Eric

    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.

    May 20th, 2008 @ 11:28 PM

  4. Eric
    Eric

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

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

    Is this not what you need?

    May 20th, 2008 @ 11:50 PM

  5. Eric
    Eric
    • 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.

    May 21st, 2008 @ 01:43 AM

  6. Eric
    Eric

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

    May 21st, 2008 @ 01:56 AM

  7. Pratik
    Pratik

    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!

    May 21st, 2008 @ 10:17 AM

  8. Jeremy Weiskotten
    Jeremy Weiskotten
    • Tag set to activerecord, edge, patch

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

    September 5th, 2008 @ 07:19 PM

  9. Eric
    Eric

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

    February 21st, 2009 @ 06:31 AM

  10. Eric
    Eric
    • 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

    March 5th, 2011 @ 06:17 AM