This project is archived and is in readonly mode.
[PATCH] ActiveRecord calculations only accept one grouping field
-
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!
-
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.
-
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?
-
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.
-
Eric
I just noticed there was a needless change of how the elements were being added to the ActiveSupport::OrderedHash.
-
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!
-
Jeremy Weiskotten
- Tag set to activerecord, edge, patch
A plugin is now available at http://github.com/patientslikeme...
-
Eric
Is there a way to un-mark this as invalid?
-
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
