Sha256: a78d8b4063f5e709185fd0ea530a467d64e4558610644635f741543151f7f318

Contents?: true

Size: 568 Bytes

Versions: 7

Compression:

Stored size: 568 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)

      context = owner.lazy_preload_context
      return if context.nil?

      association_tree_builder = AssociationTreeBuilder.new(context.association_tree)
      subtree = association_tree_builder.subtree_for(reflection.name)

      lazy_preload!(subtree)
    end

    delegate :owner, :reflection, to: :proxy_association
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ar_lazy_preload-0.2.5 lib/ar_lazy_preload/active_record/association_relation.rb
ar_lazy_preload-0.2.4 lib/ar_lazy_preload/active_record/association_relation.rb
ar_lazy_preload-0.2.3 lib/ar_lazy_preload/active_record/association_relation.rb
ar_lazy_preload-0.2.2 lib/ar_lazy_preload/active_record/association_relation.rb
ar_lazy_preload-0.2.1 lib/ar_lazy_preload/active_record/association_relation.rb
ar_lazy_preload-0.2.0 lib/ar_lazy_preload/ext/association_relation.rb
ar_lazy_preload-0.1.1 lib/ar_lazy_preload/ext/association_relation.rb