module Sequel::Plugins::ForbidLazyLoad::InstanceMethods
Public Instance Methods
Source
# File lib/sequel/plugins/forbid_lazy_load.rb 147 def allow_lazy_load 148 @forbid_lazy_load = false 149 self 150 end
Set this model instance to allow lazy loading of associations.
Source
# File lib/sequel/plugins/forbid_lazy_load.rb 153 def forbid_lazy_load 154 @forbid_lazy_load = true 155 self 156 end
Set this model instance to not allow lazy loading of associations.
Private Instance Methods
Source
# File lib/sequel/plugins/forbid_lazy_load.rb 161 def _load_associated_object(opts, dynamic_opts) 162 # The implementation that loads these associations does 163 # .all.first, which would result in the object returned being 164 # marked as forbidding lazy load. 165 obj = super 166 obj.allow_lazy_load if obj.is_a?(InstanceMethods) 167 obj 168 end
Allow lazy loading for objects returned by singular associations.
Calls superclass method
Source
# File lib/sequel/plugins/forbid_lazy_load.rb 172 def _load_associated_objects(opts, dynamic_opts=OPTS) 173 case dynamic_opts[:forbid_lazy_load] 174 when false 175 # nothing 176 when nil 177 unless dynamic_opts[:reload] 178 case opts[:forbid_lazy_load] 179 when nil 180 raise Error, "lazy loading forbidden for this object (association: #{opts.inspect}, object: #{inspect})" if @forbid_lazy_load 181 when false 182 # nothing 183 else 184 raise Error, "lazy loading forbidden for this association (#{opts.inspect})" 185 end 186 end 187 else 188 raise Error, "lazy loading forbidden for this association method call (association: #{opts.inspect})" 189 end 190 191 super 192 end
Raise an Error
if lazy loading has been forbidden for the instance, association, or call.
Calls superclass method