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

54 views
Skip to first unread message

佑馬光吉

unread,
Jan 28, 2018, 8:31:16 AM1/28/18
to Ruby on Rails: Core
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.

Alberto Almagro

unread,
Jan 29, 2018, 1:17:09 PM1/29/18
to Ruby on Rails: Core
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

Tchoum Tux

unread,
May 8, 2018, 10:13:06 PM5/8/18
to Ruby on Rails: Core
it might be necessary to replay ordered events stored in DB

James Coleman

unread,
May 9, 2018, 2:34:29 AM5/9/18
to rubyonra...@googlegroups.com
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). 
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages