[Feature Request] [Active record] - Add order option to "find_in_batches" and

Currently, if “primary_key” does not exist, “find_in_batches” and “find_each” will result in an error.

Since there may be cases where “primary_key” does not exist when performing batch processing,

I think that it can be solved by adding an order option.

Hi,

in my opinion I would order by something in cases where few objets are retrieved from DB, for example when showing a result on a template to an end user. On the other side I would use find_in_batches or find_each for background jobs or queries dealing with lots of objects to reduce memory consumption… and in those cases I don’t feel like any order is needed. Why do you think it is important to have them ordered?

Kind regards,

Alberto Almagro

it might be necessary to replay ordered events stored in DB

Fundamentally it’s not efficiently possible to find items in batches without a unique orderable value and and defined ordering by that value, because otherwise you’d have to always include a list excluding everything else you’ve already gotten (and even then you’d need a unique value/set of columns to do that).