module Sequel::Plugins::ForbidLazyLoad::InstanceMethods
def _load_associated_object(opts, dynamic_opts)
def _load_associated_object(opts, dynamic_opts) # The implementation that loads these associations does # .all.first, which would result in the object returned being # marked as forbidding lazy load. obj = super obj.allow_lazy_load if obj.is_a?(InstanceMethods) obj end
def _load_associated_objects(opts, dynamic_opts=OPTS)
Raise an Error if lazy loading has been forbidden for
def _load_associated_objects(opts, dynamic_opts=OPTS) case dynamic_opts[:forbid_lazy_load] when false # nothing when nil unless dynamic_opts[:reload] case opts[:forbid_lazy_load] when nil raise Error, "lazy loading forbidden for this object (association: #{opts.inspect}, object: #{inspect})" if @forbid_lazy_load when false # nothing else raise Error, "lazy loading forbidden for this association (#{opts.inspect})" end end else raise Error, "lazy loading forbidden for this association method call (association: #{opts.inspect})" end super end
def allow_lazy_load
def allow_lazy_load @forbid_lazy_load = false self end
def forbid_lazy_load
def forbid_lazy_load @forbid_lazy_load = true self end