module Sequel::Plugins::TacticalEagerLoading::InstanceMethods

Attributes

retrieved_by[RW]

The dataset that retrieved this object, set if the object was reteived via Dataset#all.

retrieved_with[RW]

All model objects retrieved with this object, set if the object was reteived via Dataset#all.

Public Instance Methods

marshallable!() click to toggle source

Remove retrieved_by and retrieved_with when marshalling. retrieved_by contains unmarshallable objects, and retrieved_with can be very large and is not helpful without retrieved_by.

Calls superclass method
    # File lib/sequel/plugins/tactical_eager_loading.rb
139 def marshallable!
140   @retrieved_by = nil
141   @retrieved_with = nil
142   super
143 end

Private Instance Methods

load_associated_objects(opts, dynamic_opts=OPTS, &block) click to toggle source

If there the association is not in the associations cache and the object was reteived via Dataset#all, eagerly load the association for all model objects retrieved with the current object.

Calls superclass method
    # File lib/sequel/plugins/tactical_eager_loading.rb
150 def load_associated_objects(opts, dynamic_opts=OPTS, &block)
151   dynamic_opts = load_association_objects_options(dynamic_opts, &block)
152   name = opts[:name]
153   eager_reload = dynamic_opts[:eager_reload]
154   if (!associations.include?(name) || eager_reload) && opts[:allow_eager] != false && retrieved_by && !frozen? && !dynamic_opts[:callback] && !dynamic_opts[:reload]
155     begin
156       objects = if eager_reload
157         retrieved_with.reject(&:frozen?)
158       else
159         retrieved_with.reject{|x| x.frozen? || x.associations.include?(name)}
160       end
161       retrieved_by.send(:eager_load, objects, name=>dynamic_opts[:eager] || OPTS)
162     rescue Sequel::UndefinedAssociation
163       # This can happen if class table inheritance is used and the association
164       # is only defined in a subclass.  This particular instance can use the
165       # association, but it can't be eagerly loaded as the parent class doesn't
166       # have access to the association, and that's the class doing the eager loading.
167       nil
168     end
169   end
170   super
171 end