Sha256: 7d7782dc20ce36f2af2cd74da51a4c4a4b169666e475a92095cfdea81778d6ee

Contents?: true

Size: 1.1 KB

Versions: 4

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

class Serega
  module SeregaPlugins
    module Batch
      #
      # Extensions (mini-plugins) that are enabled when :batch plugin used with other plugins
      #
      module PluginsExtensions
        #
        # Extension that is used when :batch plugin used with :active_record_preloads plugin
        #
        module ActiveRecordPreloads
          #
          # BatchLoader additional/patched instance methods
          #
          # @see Serega::SeregaPlugins::Batch::SeregaBatchLoader
          #
          module BatchLoaderInstanceMethods
            private

            # Preloads required associations to batch-loaded records
            def keys_values(*)
              data = super

              if point.has_nested_points?
                associations = point.preloads
                return data if associations.empty?

                records = data.values
                records.flatten!(1)

                ActiverecordPreloads::Preloader.preload(records, associations)
              end

              data
            end
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
serega-0.10.0 lib/serega/plugins/batch/lib/plugins_extensions/activerecord_preloads.rb
serega-0.9.0 lib/serega/plugins/batch/lib/plugins_extensions/activerecord_preloads.rb
serega-0.8.3 lib/serega/plugins/batch/lib/plugins_extensions/activerecord_preloads.rb
serega-0.8.2 lib/serega/plugins/batch/lib/plugins_extensions/activerecord_preloads.rb