Re: [Rails] Re: Using group_to() and aggregation for a simple inventory system @ a field hospital in Haiti

2010-03-17 Thread Michael Pavling
On 17 March 2010 13:33, Clay H. wrote: > the only issue is that amount_on_hand is a method > in the Medicine model, not in the Stock model -- it performs an > aggregate sum for all of the stocks belonging to the medicine in > question. This code uses it as a Stock method, doesn't it? Of course -

[Rails] Re: Using group_to() and aggregation for a simple inventory system @ a field hospital in Haiti

2010-03-17 Thread Clay H.
On Mar 16, 12:45 pm, Michael Pavling wrote: > On 16 March 2010 15:57, Michael Pavling wrote: > > >> Also, is it possible to order the hash so that they appear in > >> descending order of how much of each item is in stock? In other words, > >> sort descending by the value that the following genera

Re: [Rails] Re: Using group_to() and aggregation for a simple inventory system @ a field hospital in Haiti

2010-03-16 Thread Michael Pavling
On 16 March 2010 15:57, Michael Pavling wrote: >> Also, is it possible to order the hash so that they appear in >> descending order of how much of each item is in stock? In other words, >> sort descending by the value that the following generates? >> >> <%=h "#{s.last.sum(&:amount_received) - >> s

Re: [Rails] Re: Using group_to() and aggregation for a simple inventory system @ a field hospital in Haiti

2010-03-16 Thread Michael Pavling
On 16 March 2010 15:33, Clay H. wrote: > On Mar 16, 8:33 am, Michael Pavling wrote: >> >> And post again if you need any more help. > > Hey, thanks for the help so far. I went with a method in the > Medicine.rb model file and I'm trying to display the results through > the view, using code simila

[Rails] Re: Using group_to() and aggregation for a simple inventory system @ a field hospital in Haiti

2010-03-16 Thread Clay H.
On Mar 16, 8:33 am, Michael Pavling wrote: > > And post again if you need any more help. Hey, thanks for the help so far. I went with a method in the Medicine.rb model file and I'm trying to display the results through the view, using code similar to what you suggested. I modified the code to app

Re: [Rails] Re: Using group_to() and aggregation for a simple inventory system @ a field hospital in Haiti

2010-03-16 Thread Michael Pavling
On 16 March 2010 12:03, Clay H. wrote: > On Mar 15, 9:25 pm, Michael Pavling wrote: >> Using Enumerable.group_by: >> >> Stock.all.group_by{|s| [s.medicine.name, s.route.name, s.strength]}.each do >> |s| >>   puts "#{s.first.inspect} #{s.last.sum(&:amount_received) - >> s.last.sum(&:amount_dispen

[Rails] Re: Using group_to() and aggregation for a simple inventory system @ a field hospital in Haiti

2010-03-16 Thread Clay H.
On Mar 15, 9:25 pm, Michael Pavling wrote: > Using Enumerable.group_by: > > Stock.all.group_by{|s| [s.medicine.name, s.route.name, s.strength]}.each do > |s| >   puts "#{s.first.inspect} #{s.last.sum(&:amount_received) - > s.last.sum(&:amount_dispensed)}" > end > > Does that give you enough to wo