rails/rails — pull request #14165 by hotgazpacho (2014-02-23 06:58:32+00:00)
Title: Allow ordered find_in_batches

SQL gives us LIMIT and OFFSET to deal with paging through a set of results. There is, therefor, no need to force ordering by the primary key. If there is no order provided, then we can force ordering by the primary key. One potential shortfall to this method: if the block yielded to `find_in_batches` ends up mutating any of the fields that have been sorted on, then you're potentially gonna have a bad time. I submit that if this is an issue, the user should either remove the orders before `find_in_batches`, or the user should explicitly order by the primary key field.