find_in_batches does not use given order but uses

2019-06-11 22:11发布

问题:

How can I use ordering as it is?

Any help will be appreciated. Thank u!

see the code-

selected_catalog_products.find_in_batches(batch_size: 4) do |cps|
  # my code
end

回答1:

It’s not possible to set the order. That is automatically set to ascending on the primary key (“id ASC”) to make the batch ordering work.

http://apidock.com/rails/ActiveRecord/Batches/find_in_batches