ActiveRecord::Base.foreach

Sep 27, 2010 10:55

Little did I know that ActiveRecord doesn't have a truly iterative way for dealing with results. You get the find method, with its various incantations of :all, :first, :limit, etc, but there's not way to iterate over every record in turn without slurping the result set into memory first ( Read more... )

oracle, ruby, rails

Leave a comment

Comments 2

anonymous September 27 2010, 16:57:59 UTC
I believe since rails 2.3.2 it provides find_in_batches and find_each. Check active_record/relation/batches.rb

Reply

djberg96 September 27 2010, 19:40:55 UTC
find_in_batches is the backend to find_each I think. But, as I mentioned, it still slurps 1000 records at a time, and it's broken in conjunction with the composite_primary_keys library.

Reply


Leave a comment

Up