method
batch_on_loaded_relation
v7.2.3 -
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|
id = record.id
if order == :asc
(start.nil? || id >= start) && (finish.nil? || id <= finish)
else
(start.nil? || id <= start) && (finish.nil? || id >= finish)
end
end
end
records.sort_by!(&:id)
if order == :desc
records.reverse!
end
records.each_slice(batch_limit) do |subrecords|
subrelation = relation.spawn
subrelation.load_records(subrecords)
yield subrelation
end
nil
end