instance method
batch_on_loaded_relation
Ruby on Rails 8.0.4
Since v7.1.6 PrivateSignature
batch_on_loaded_relation(relation:, start:, finish:, cursor:, order:, batch_limit:)
No documentation comment.
Parameters
-
relationkeyreq -
startkeyreq -
finishkeyreq -
cursorkeyreq -
orderkeyreq -
batch_limitkeyreq
Source
# File activerecord/lib/active_record/relation/batches.rb, line 379
def batch_on_loaded_relation(relation:, start:, finish:, cursor:, order:, batch_limit:)
records = relation.to_a
order = build_batch_orders(cursor, order).map(&:second)
if start || finish
records = records.filter do |record|
values = record_cursor_values(record, cursor)
(start.nil? || compare_values_for_order(values, Array(start), order) >= 0) &&
(finish.nil? || compare_values_for_order(values, Array(finish), order) <= 0)
end
end
records.sort! do |record1, record2|
values1 = record_cursor_values(record1, cursor)
values2 = record_cursor_values(record2, cursor)
compare_values_for_order(values1, values2, order)
end
records.each_slice(batch_limit) do |subrecords|
subrelation = relation.spawn
subrelation.load_records(subrecords)
yield subrelation
end
nil
end
Defined in activerecord/lib/active_record/relation/batches.rb line 379
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::Batches