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
143 def marshallable!
144   @retrieved_by = nil
145   @retrieved_with = nil
146   super
147 end

Private Instance Methods

_filter_tactical_eager_load_objects(opts) click to toggle source

Filter the objects used when tactical eager loading. By default, this removes frozen objects and objects that alreayd have the association loaded, as well as objects where the reflection for the association is not the same as the receiver’s reflection for the association.

Calls superclass method
    # File lib/sequel/plugins/tactical_eager_loading.rb
168 def _filter_tactical_eager_load_objects(opts)
169   objects = defined?(super) ? super : retrieved_with.dup
170   name = opts[:name]
171   if opts[:eager_reload]
172     objects.reject!(&:frozen?)
173   else
174     objects.reject!{|x| x.frozen? || x.associations.include?(name)}
175   end
176   reflection = self.class.association_reflection(name)
177   objects.select!{|x| x.class.association_reflection(name).equal?(reflection)}
178   objects
179 end
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
154 def load_associated_objects(opts, dynamic_opts=OPTS, &block)
155   dynamic_opts = load_association_objects_options(dynamic_opts, &block)
156   name = opts[:name]
157   eager_reload = dynamic_opts[:eager_reload]
158   if (!associations.include?(name) || eager_reload) && opts[:allow_eager] != false && retrieved_by && !frozen? && !dynamic_opts[:callback] && !dynamic_opts[:reload]
159     retrieved_by.send(:eager_load, _filter_tactical_eager_load_objects(:eager_reload=>eager_reload, :name=>name), {name=>dynamic_opts[:eager] || OPTS}, model)
160   end
161   super
162 end