title: Group Query with Calculations on Rails 3
body: <p>Rails 3 problem.
  I have a Foods table of foods with the following attributes:</p>
  
  <ul>
  <li>name</li>
  <li>calories (per gram)</li>
  <li>fat (per gram)</li>
  <li>carbs (per gram)</li>
  <li>protein (per gram)</li>
  </ul>
  
  <p>I then have a LoggedFoods table representing a food that has been eaten at a given time. It has the following attributes:</p>
  
  <ul>
  <li>food_id</li>
  <li>number_of_grams_eaten</li>
  <li>ate_when (datetime)</li>
  </ul>
  
  <p>So the problem I have is that I'd like to get the total number of calories, fat, protein, carbs consumed per day (for all days) in one query. I've been trying to do this Rails 3 using the new ActiveRecord query interface and had no luck. Any ideas?</p>