Sha256: 8005eace0f2b273df48d3ae79a6baef4438cd42c6eb31733768e65bbc47bc2e3

Contents?: true

Size: 929 Bytes

Versions: 3

Compression:

Stored size: 929 Bytes

Contents

# frozen_string_literal: true

module N1Loader
  module ActiveRecord
    module Associations
      module Preloader # :nodoc:
        N1LoaderReflection = Struct.new(:name, :loader) do
          def options
            {}
          end
        end

        def preloaders_for_reflection(reflection, records, scope)
          return super unless reflection.is_a?(N1LoaderReflection)

          N1Loader::Preloader.new(records).preload(reflection.name)
        end

        def grouped_records(association, records, polymorphic_parent)
          n1_load_records, records = records.partition do |record|
            record.class.respond_to?(:n1_loaders) && record.class.n1_loaders[association]
          end

          hash = n1_load_records.group_by do |record|
            N1LoaderReflection.new(association, record.class.n1_loaders[association])
          end

          hash.merge(super)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
n1_loader-1.7.4 lib/n1_loader/active_record/associations_preloader_v6.rb
n1_loader-1.7.3 lib/n1_loader/active_record/associations_preloader_v6.rb
n1_loader-1.7.2 lib/n1_loader/active_record/associations_preloader_v6.rb