title: Rails sum model def instead of column
body: <p>I have a Rails app that includes invoicing.</p>
  
  <p>I use this def in the invoice controller:</p>
  
  <pre><code>def invoice_total
    self.invtimes.sum('price') + self.invexpenses.sum('price') + self.invaddhocs.sum('price') + self.invitems.sum('price') - self.payments.sum('amount')
  end
  </code></pre>
  
  <p>Is there a way to sum <code>invoice_total</code> ?</p>
  
  <p>I tried this:</p>
  
  <pre><code>&lt;td&gt;&lt;%= Invoice.notdraft.where("invoice_date &gt;= ? AND invoice_date &lt; ?", janday, febday).sum(:invoice_total) %&gt;&lt;/td&gt;
  </code></pre>
  
  <p>But, Rails tells me:</p>
  
  <pre><code>PG::Error: ERROR:  column "invoice_total" does not exist
  </code></pre>
  
  <p>Thanks for the help!</p>