module ArLazyPreload::AssociationRelation

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

Public Class Methods

new(*args) click to toggle source
Calls superclass method
# File lib/ar_lazy_preload/active_record/association_relation.rb, line 7
def initialize(*args)
  super(*args)
  setup_preloading_context unless ArLazyPreload.config.auto_preload?
end

Private Instance Methods

setup_preloading_context() click to toggle source
# File lib/ar_lazy_preload/active_record/association_relation.rb, line 17
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