Module: EagerRecord::EagerPreloading::AssociationCollectionExtensions

Defined in:
lib/eager_record/eager_preloading.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



61
62
63
64
65
# File 'lib/eager_record/eager_preloading.rb', line 61

def self.included(base)
  base.module_eval do
    alias_method_chain :load_target, :eager_preloading
  end
end

Instance Method Details

#load_target_with_eager_preloadingObject



67
68
69
70
71
72
73
74
75
76
77
# File 'lib/eager_record/eager_preloading.rb', line 67

def load_target_with_eager_preloading
  if @reflection.options[:conditions].nil? && (!@owner.new_record? || foreign_key_present)
    if !loaded?
      if originating_collection = @owner.instance_variable_get(:@originating_collection)
        @owner.class.__send__(:preload_associations, originating_collection, @reflection.name)
        return target if loaded?
      end
    end
  end
  load_target_without_eager_preloading
end