Sha256: 2b303bd77bbbb3a14a978a0e804393a001280faa0e71deca625c6751689aad51

Contents?: true

Size: 834 Bytes

Versions: 8

Compression:

Stored size: 834 Bytes

Contents

# frozen_string_literal: true

module ArLazyPreload
  # ActiveRecord::AssociationRelation patch for setting up lazy_preload_values based on
  # owner context
  module AssociationRelation
    def initialize(*args)
      super(*args)
      setup_preloading_context unless ArLazyPreload.config.auto_preload?
    end

    delegate :owner, :reflection, to: :proxy_association, prefix: true
    delegate :lazy_preload_context, to: :proxy_association_owner

    private

    def setup_preloading_context
      return if lazy_preload_context.nil?
      return if lazy_preload_context.association_tree.nil?

      association_tree_builder = AssociationTreeBuilder.new(lazy_preload_context.association_tree)
      subtree = association_tree_builder.subtree_for(proxy_association_reflection.name)

      lazy_preload!(subtree)
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ar_lazy_preload-2.1.0 lib/ar_lazy_preload/active_record/association_relation.rb
ar_lazy_preload-2.0.0 lib/ar_lazy_preload/active_record/association_relation.rb
ar_lazy_preload-1.1.2 lib/ar_lazy_preload/active_record/association_relation.rb
ar_lazy_preload-1.1.1 lib/ar_lazy_preload/active_record/association_relation.rb
ar_lazy_preload-1.1.0 lib/ar_lazy_preload/active_record/association_relation.rb
ar_lazy_preload-1.0.0 lib/ar_lazy_preload/active_record/association_relation.rb
ar_lazy_preload-0.7.0 lib/ar_lazy_preload/active_record/association_relation.rb
ar_lazy_preload-0.6.2 lib/ar_lazy_preload/active_record/association_relation.rb