title: Rails: iterating over all objects of a type without loading them all at once
body: <pre><code>class Car &lt;&lt; ActiveRecord::Base
  end
  
  Car.all.each do |car|
    # do stuff
  end
  </code></pre>
  
  <p>This loads all the objects of type Car into memory (I think) and iterates through them. What I want instead is to iterate through all the ids and load them one at a time like this:</p>
  
  <pre><code>Car.all_ids.each do |id|
    c = Car.find id
    # do stuff
  end
  </code></pre>
  
  <p>But all_ids doesn't exist, is there an equivalent?</p>