title: Rails - counter_cache for total sum
body: <p>I have <code>Transactions</code> table which is the M:M table between <code>Users</code> and <code>Products</code>.</p>
  
  <pre><code>class Transaction
    belongs_to :user
    belongs_to :product, counter_cache: :transactions_count
  end
  </code></pre>
  
  <p>Inside Transaction table, I have <code>quantity</code> column.</p>
  
  <p>While inside Products, I have <code>transactions_count</code> which stores how many times this product has been purchased.</p>
  
  <p>But that counter cache only count the <strong>number of rows</strong>. Is there a way to count the <strong>sum of quantity</strong>?</p>
  
  <p>I know I can use something like <code>after_save :update_count</code>, but is there a <strong>Rails convention</strong> that when followed will automate this task?</p>
  
  <p>Thanks</p>