method
batch_on_loaded_relation
v7.1.3.4 -
Show latest stable
- Class:
ActiveRecord::Batches
batch_on_loaded_relation(relation:, start:, finish:, order:, batch_limit:)private
No documentation available.
# File activerecord/lib/active_record/relation/batches.rb, line 339
def batch_on_loaded_relation(relation,, start,, finish,, order,, batch_limit))
records = relation.to_a
if start || finish
records = records.filter do |record|
(start.nil? || record.id >= start) && (finish.nil? || record.id <= finish)
end
end
records = records.sort_by { |record| record.id }
if order == :desc
records.reverse!
end
(0...records.size).step(batch_limit).each do |start|
subrelation = relation.spawn
subrelation.load_records(records[start, batch_limit])
yield subrelation
end
nil
end