title: Rails: Order by sum of two columns
body: <p>So, I have a <code>Photo</code> model which can be downloaded at <code>full_size</code> and <code>presentation_size</code>. When a user downloads a photo I track this on the photo's <code>full_downloads</code> and <code>presentation_downloads</code> attribute.</p>
  
  <p>That's all good.</p>
  
  <p>Sometimes I want to know how many total downloads there have been. I have a simple method, <code>total_downloads</code> which looks like so:</p>
  
  <pre><code>def total_downloads
    self.full_downloads + self.presentation_downloads
  end
  </code></pre>
  
  <p><strong>My question is:</strong> I would like to be able to order photos by all three of these (full, presentation, total downloads). The first two are easy, but how do you do an order by the sum of two columns? Note this needs to be both SQLite and PG compatible at minimum.</p>
  
  <p>A side question, would it be faster to make the <code>total_downloads</code> method a query, and if so what's the best way to write that? I know to sum on the class you can call <code>Photo.sum(...)</code>, but I'm not sure how to do that for two columns on a single record.</p>
  
  <p>Thanks!</p>