On 15 March 2010 22:07, Clay H. <[email protected]> wrote:
> I've been reading on the group_by() method for enumeration
>
> Any help with this method or suggestions for alternative approaches
> would be appreciated! I'd like to get the system updated as soon as I
> can. Thanks!


You might get a quicker result by doing a query direct to the DB and
using its GROUP BY functionality:

SELECT sum( s.amount_received ) - sum(amount_dispensed) as
amount_on_hand, s.strength, r.name AS route, m.name AS medicine
FROM stocks s
JOIN medicines m ON s.medicine_id = m.id
JOIN routes r ON s.route_id = r.id
GROUP BY s.strength, r.name, m.name

You can use this in a "find_by_sql" and iterate it as a normal array....

Not exactly Rails-y. but let's face it, we need to know what drugs are
in the cupboard right now.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to