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
_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
Calls superclass method
# File lib/sequel/plugins/tactical_eager_loading.rb 162 def _filter_tactical_eager_load_objects(opts) 163 objects = defined?(super) ? super : retrieved_with.dup 164 if opts[:eager_reload] 165 objects.reject!(&:frozen?) 166 else 167 name = opts[:name] 168 objects.reject!{|x| x.frozen? || x.associations.include?(name)} 169 end 170 objects 171 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 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