title: Rails: How do I filter a ActiveRecord collection result without making new db queries?
body: <p>Say I have a <code>Candle</code> model with '<code>today</code>' scope. The scope runs a few heavy conditions and gives me around 5k rows as the result.</p>
  
  <pre><code>today_candles = Candle.today
  </code></pre>
  
  <p>I want to later filter this collection with a column value. For eg:</p>
  
  <pre><code>aaa_candles = today_candles.where(type: 'AAA')
  bbb_candles = today_candles.where(type: 'BBB')
  ...
  </code></pre>
  
  <p><strong>But</strong> each of this filter is making a new db request as follows:</p>
  
  <pre><code>Candle.today.where(type: 'AAA')
  Candle.today.where(type: 'BBB')
  ...
  </code></pre>
  
  <p>Is there a way to filter on the initial collection <code>today_candles</code> data without making new multiple db requests? It feels like a basic functionality but I cannot find it.</p>
  
  <p>I am currently storing the collection as an array and then looping through them to filter and avoid multiple db calls. But this feels stupid.</p>
  
  <p><em>Please note:</em> I'm not sure if Rails does cache the AR collection and filter them without new db_queries in a production environment. I'm currently on webrick (development).</p>