afaik, there's no special finder for collecting together three sums in
a single query. You'll need to get your hands mildly dirty with SQL.
Javier points out easiest solution with one tweak -- drop the colons:
sums = Order.find(:all, :select=>'sum(item_total) AS item,
sum(shipping_total) AS ship, sum(tax_total) AS tax').first @itemsum = sums[:item] @shipsum = sums[:ship] @taxsum = sums[:tax]
afaik, there's no special finder for collecting together three sums in
a single query. You'll need to get your hands mildly dirty with SQL.
Javier points out easiest solution with one tweak -- drop the colons:
right.. lazy me... i c/pasted the fields into the sentence and i didn't realize i was taking the colons with me
afaik, there's no special finder for collecting together three sums in
a single query. You'll need to get your hands mildly dirty with SQL.
Javier points out easiest solution with one tweak -- drop the colons:
sums = Order.find(:all, :select=>'sum(item_total) AS item,
sum(shipping_total) AS ship, sum(tax_total) AS tax').first @itemsum = sums[:item] @shipsum = sums[:ship] @taxsum = sums[:tax]
So, this approach gives me an inaccurate number:
-------------------------------------------------------------
sums = Order.find(:all, :select=>'sum(item_total) AS item,
sum(shipping_total) AS ship, sum(tax_total) AS tax').first