module Sequel::Plugins::TacticalEagerLoading::InstanceMethods
Attributes
The dataset that retrieved this object, set if the object was reteived via Dataset#all
.
All model objects retrieved with this object, set if the object was reteived via Dataset#all
.
Public Instance Methods
Source
# File lib/sequel/plugins/tactical_eager_loading.rb 139 def marshallable! 140 @retrieved_by = nil 141 @retrieved_with = nil 142 super 143 end
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.
Private Instance Methods
Source
# File lib/sequel/plugins/tactical_eager_loading.rb 164 def _filter_tactical_eager_load_objects(opts) 165 objects = defined?(super) ? super : retrieved_with.dup 166 name = opts[:name] 167 if opts[:eager_reload] 168 objects.reject!(&:frozen?) 169 else 170 objects.reject!{|x| x.frozen? || x.associations.include?(name)} 171 end 172 reflection = self.class.association_reflection(name) 173 objects.select!{|x| x.class.association_reflection(name).equal?(reflection)} 174 objects 175 end
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.
Source
# 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 retrieved_by.send(:eager_load, _filter_tactical_eager_load_objects(:eager_reload=>eager_reload, :name=>name), {name=>dynamic_opts[:eager] || OPTS}, model) 156 end 157 super 158 end
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.