title: How can I select a SUM in a query using Rails 3 / MetaSearch?
body: <p>I have a Rails 3 application where my model includes Owners and Properties, each Owner representing a person or institution that owns one or more properties.</p>
  
  <p>I would like to be able to search my database (SQLite3) and return the results grouped by owner.  For each group, I would like to display:</p>
  
  <p>-The owner's name (I can do this easily)
  -The total number of properties belonging to this owner that meet the search conditions (i.e., a count).
  -The total value of all the properties counted in the previous column (i.e., a sum).</p>
  
  <p>Owner has_many Properties, and Property belongs_to Owner.  Also, "value" is an attribute for Property.</p>
  
  <p>I am using the MetaSearch gem, and I can get it to return a collection of properties correctly.  I can also get it to group the results by owner, but I can't figure out how to display the number of properties and their summed value.</p>
  
  <p>Here is the code to return the list of properties:</p>
  
  <pre><code>@search = Property.group("owner_id").search(params[:search])
  </code></pre>
  
  <p>I have tried adding a .select to the chain like this:</p>
  
  <pre><code>@search = Property.select("SUM(value) as mysum").group("owner_id").search(params[:search])
  </code></pre>
  
  <p>But I can't access this sum when I try.  Does anyone know of an efficient way of handling this situation?</p>