title: SUM operation on attributes of children of multiple parent records
body: <p>I have this method in my Product model that does what I need:</p>
  
  <pre><code>def self.available
    available = []
    Product.all.each do |product|
      if product.quantity &gt; product.sales.sum(:quantity)
        available &lt;&lt; product
      end
    end
    return available
  end
  </code></pre>
  
  <p>But, I am wondering if there is a more efficient way to do this, maybe with only one call to the database.</p>