title: How order items based on votes
body: <p>I am trying to render a list of the top 10 photos ordered by their votes this is how I decided to do it:</p>
  
  <pre><code>@top_photos = Photo.all(:joins =&gt; :votes, :select =&gt; "photos.*, count(*) as vote_total",:group =&gt; "votes.photo_id", :order =&gt; "vote_total DESC" )#, :limit =&gt; 10)
  </code></pre>
  
  <p>but i am getting the following error from my heroku logs:</p>
  
  <pre><code>ActiveRecord::StatementInvalid (PGError: ERROR:  column "photos.id" must appear in the GROUP BY clause or be used in an aggregate function
  </code></pre>
  
  <p>Works find on localhost with sqlite but does not work at all with postgres on heroku. Looking for some insight on what this may be or just an alternative way to achieve the same thing.
  Cheers</p>