method

batch_on_loaded_relation

Importance_0
v8.1.1 - Show latest stable - 0 notes - Class: ActiveRecord::Batches
batch_on_loaded_relation(relation:, start:, finish:, cursor:, order:, batch_limit:) private

No documentation

This method has no description. You can help the Ruby on Rails community by adding new notes.

Hide 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
Register or log in to add new notes.