title: Group and count in Rails
body: <p>I have this bit of code and I get an empty object.</p>
  
  <pre><code>@results = PollRoles.find(
              :all, 
              :select =&gt; 'option_id, count(*) count', 
              :group =&gt; 'option_id', 
              :conditions =&gt; ["poll_id = ?", @poll.id])
  </code></pre>
  
  <p>Is this the correct way of writing the query? I want a collection of records that have an option id and the number of times that option id is found in the PollRoles model.</p>
  
  <p><strong>EDIT:</strong> This is how I''m iterating through the results:</p>
  
  <pre><code>&lt;% @results.each do |result| %&gt;
              &lt;% @option = Option.find_by_id(result.option_id) %&gt;
              &lt;%= @option.question %&gt; &lt;%= result.count %&gt;
          &lt;% end %&gt;
  </code></pre>