Sha256: e153ffa7b1d34af2b1889a7e5b7e1ec8e0d5ee06b5cade3defd87aa73baaa071

Contents?: true

Size: 1.09 KB

Versions: 13

Compression:

Stored size: 1.09 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.child_plan
                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

13 entries across 13 versions & 1 rubygems

Version Path
serega-0.21.0 lib/serega/plugins/batch/lib/plugins_extensions/activerecord_preloads.rb
serega-0.20.1 lib/serega/plugins/batch/lib/plugins_extensions/activerecord_preloads.rb
serega-0.20.0 lib/serega/plugins/batch/lib/plugins_extensions/activerecord_preloads.rb
serega-0.19.0 lib/serega/plugins/batch/lib/plugins_extensions/activerecord_preloads.rb
serega-0.18.0 lib/serega/plugins/batch/lib/plugins_extensions/activerecord_preloads.rb
serega-0.17.0 lib/serega/plugins/batch/lib/plugins_extensions/activerecord_preloads.rb
serega-0.16.0 lib/serega/plugins/batch/lib/plugins_extensions/activerecord_preloads.rb
serega-0.15.0 lib/serega/plugins/batch/lib/plugins_extensions/activerecord_preloads.rb
serega-0.14.0 lib/serega/plugins/batch/lib/plugins_extensions/activerecord_preloads.rb
serega-0.12.0 lib/serega/plugins/batch/lib/plugins_extensions/activerecord_preloads.rb
serega-0.11.2 lib/serega/plugins/batch/lib/plugins_extensions/activerecord_preloads.rb
serega-0.11.1 lib/serega/plugins/batch/lib/plugins_extensions/activerecord_preloads.rb
serega-0.11.0 lib/serega/plugins/batch/lib/plugins_extensions/activerecord_preloads.rb