title: Group By multiple column for sql count statement , in rails environment
body: <p>I have two Relations (class)</p>
  
  <pre><code>class RecommendedForType &lt; ActiveRecord::Base
     attr_accessible :description, :name
     has_many :recommended_for_type_restaurants
  end
  </code></pre>
  
  <p>And</p>
  
  <pre><code>class RecommendedForTypeRestaurant &lt; ActiveRecord::Base
     attr_accessible :recommended_for_type_id, :restaurant_id, :user_id
     belongs_to :restaurant
     belongs_to :user
     belongs_to :recommended_for_type
  
     def self.get_count(rest_id)
       r = RecommendedForTypeRestaurant.where(restaurant_id: rest_id)
       @result =  r.includes(:recommended_for_type)
              .select("recommended_for_type_id, recommended_for_types.name")
              .group ("recommended_tor_type_id, recommended_for_types.name")
              .count
     end
  
  end
  </code></pre>
  
  <p>if I call </p>
  
  <pre><code> RecommendedForTypeRestaurant.get_count(1) # get stat of restaurant_id: 1
  </code></pre>
  
  <p>I get</p>
  
  <pre><code> {"dinner"=&gt;1, "fast food"=&gt;1, "lunch"=&gt;3, "romantic dinner"=&gt;1}
  </code></pre>
  
  <p>My goal is to get both <code>id</code> and <code>name</code>  of <code>RecommendTypeFor</code> in the return result as well. currently i can only make it return either <code>id</code> or <code>name</code>. Something like this</p>
  
  <pre><code> {{"id" =&gt; 1, "name" =&gt; "dinner", "count" =&gt; 1}, {"id" =&gt;2, "name" =&gt; "lunch", "count" =&gt; 3} }
  </code></pre>
  
  <p>For sure i can do another round of sql once i get id or name to create that hash but i think that not the efficient way. Appreciate any help or suggestion :) </p>