title: Rails group by foreign key with custom rules
body: <p>I have the following <code>tables</code>/<code>models</code> in my helpdesk module.</p>
  
  <p><strong>status.rb</strong></p>
  
  <pre><code>has_many :tickets
  </code></pre>
  
  <p><strong>Statuses table</strong></p>
  
  <pre><code>id         name
  ----------------------
  1          New
  2          Assigned
  3          In progress
  4          Finished
  5          Closed
  6          Cancelled
  </code></pre>
  
  <p><strong>ticket.rb</strong></p>
  
  <pre><code>belongs_to :status
  </code></pre>
  
  <p><strong>Tickets table</strong></p>
  
  <pre><code>id    status_id   subject    customer_id
  ----------------------------------------
  1     1           Ticket 1   1
  2     1           Ticket 2   1
  3     2           Ticket 3   1
  4     3           Ticket 4   1
  5     4           Ticket 5   1
  6     3           Ticket 6   1
  7     1           Ticket 7   1
  8     2           Ticket 8   1
  </code></pre>
  
  <p>For helpdesk team, i need to show tickets count by status.</p>
  
  <p>This would work for it,</p>
  
  <pre><code>Ticket.all.joins(:status).group("statuses.name").count
   =&gt; {"New" =&gt; 3, "Assigned" =&gt; 2, "In progress" =&gt; 2, "Finished" =&gt; 1} 
  </code></pre>
  
  <p>Now the problem is, I want to show <code>Assigned</code> and <code>In progress</code> as single group, <code>Active</code>, to customers.</p>
  
  <p>The result should look like this, </p>
  
  <pre><code>=&gt; {"New" =&gt; 3, "Active" =&gt; 4, "Finished" =&gt; 1} 
  </code></pre>
  
  <p>How can I get this result using?</p>