Module: ArLazyPreload::AssociationRelation

Defined in:
lib/ar_lazy_preload/ext/association_relation.rb

Overview

ActiveRecord::AssociationRelation patch for setting up lazy_preload_values based on owner context

Instance Method Summary collapse

Instance Method Details

#initialize(*args) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/ar_lazy_preload/ext/association_relation.rb', line 7

def initialize(*args)
  super(*args)

  context = owner.lazy_preload_context
  return if context.blank?

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

  lazy_preload!(subtree)
end