title: Rails 3 scope, combine condition with aggregate (sum) results in error
body: <p>I am having what I think is a simple problem chaining two scopes (Rails 3.2.5).</p>
  
  <p>I have a model called <code>Point</code> with fields <code>amount</code> and <code>transaction_date</code>, amongst other.  Users get an amount of points for various activities, and they are "available" until used, which happens as part of a transaction, at which point <code>transaction_date</code> is updated, and no longer empty.</p>
  
  <p>So I have a scope like this:</p>
  
  <pre><code>scope :available, where("transaction_date IS NULL OR transaction_date = ''")
  </code></pre>
  
  <p>and it works great, returning the proper collection of Point objects.  So I can do</p>
  
  <pre><code>&gt; Point.available
  =&gt; [#&lt;Point id: 123, amount: 22, transaction_date: nil &gt;][#&lt;Point id: 456, amount: 33, transaction_date: nil &gt;]
  </code></pre>
  
  <p>And if I want to know the sum of available points, I can do</p>
  
  <pre><code>&gt; Point.available.sum("amount")
  =&gt; 55
  </code></pre>
  
  <p>But if I try to make another scope like</p>
  
  <pre><code>scope :available, where("transaction_date IS NULL OR transaction_date = ''")
  scope :total_available, available.sum("amount")
  </code></pre>
  
  <p>I get the error</p>
  
  <pre><code>NoMethodError: undefined method `default_scoped?' for 22:Fixnum
  </code></pre>
  
  <p>or if I change the scope so it's <code>sum("amount").available</code> I get the error</p>
  
  <pre><code>NoMethodError: undefined method `available' for 55:Fixnum
  </code></pre>
  
  <p>I can also make the <code>:total_available</code> scope work by adding the condition defined in <code>:available</code>, but that's not very DRY.</p>
  
  <p>What am I missing here?</p>