instance method batch_on_loaded_relation

Ruby on Rails 7.1.6

Since v7.1.6 Private

Available in: v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

batch_on_loaded_relation(relation:, start:, finish:, order:, batch_limit:)

No documentation comment.

Parameters

relation keyreq
start keyreq
finish keyreq
order keyreq
batch_limit keyreq
Source
# 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

Defined in activerecord/lib/active_record/relation/batches.rb line 339 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveRecord::Batches

Type at least 2 characters to search.

↑↓ navigate · open · esc close