Search Results

Search found 2 results on 1 pages for 'alamodey'.

Page 1/1 | 1 

  • Group and count in Rails

    - by alamodey
    I have this bit of code and I get an empty object. @results = PollRoles.find( :all, :select => 'option_id, count(*) count', :group => 'option_id', :conditions => ["poll_id = ?", @poll.id]) 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. EDIT: This is how I''m iterating through the results: <% @results.each do |result| %> <% @option = Option.find_by_id(result.option_id) %> <%= @option.question %> <%= result.count %> <% end %>

    Read the article

1