method

batch_on_loaded_relation

Importance_0
v7.1.3.4 - Show latest stable - 0 notes - Class: ActiveRecord::Batches
batch_on_loaded_relation(relation:, start:, finish:, 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 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
Register or log in to add new notes.