This project is archived and is in readonly mode.
[patch] AR::Base Reverse find_in_batches.
I wanted to find the most recent 200 items that matched a function (could not be done in the DB). Hits where fairly sparse, so it could mean scanning the whole database (millions of rows), and still not hitting that magic 200.
find_each fitted the bill perfectly.
Apart from it would only work in ascending order.
So I monkey patched find_in_batches, it worked, I was happy.
I wanted others to be happy, so I did a patch, and made it respect limits too.
Anyone fancy taking it for a test drive? Is this useful to anyone but me?
Thanks - Tom
(patch was against 2-3-stable)
Comments and changes to this ticket
i see the point of the order thing, but not of the limit - there is already a batch size ?
tested with mysql - the tests run, but i would add test with :order => :asc too. I know that's the default too, but someone's bound to specify it if the option exists (in the foolproof category).
tested the (only slightly) modified patch with
undef_method': undefined methodid' for class
ActiveRecord::Base' (NameError)<br/> probably due to something else, and it occurs with all above dbs.
- State changed from new to wontfix
This function is deliberately limited to primary_key order because those values don't change. If you order by title and manipulate the title in your block, you'll get nonsense / repeated options back.
It's only intended for iterating over the whole collection in primary_key order.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
Tickets have moved to Github
The new ticket tracker is available at https://github.com/rails/rails/issues