module Sequel::Plugins::ManyToOnePkLookup::InstanceMethods

Private Instance Methods

_load_associated_objects(opts, dynamic_opts={}) click to toggle source

If the current association is a simple many_to_one association, use a simple primary key lookup on the associated model, which can benefit from caching if the associated model is using caching.

Calls superclass method
# File lib/sequel/plugins/many_to_one_pk_lookup.rb, line 42
def _load_associated_objects(opts, dynamic_opts={})
  return super unless opts.can_have_associated_objects?(self) && opts[:type] == :many_to_one
  klass = opts.associated_class
  if !dynamic_opts[:callback] &&
     opts.send(:cached_fetch, :many_to_one_pk_lookup){opts.primary_key == klass.primary_key}
    klass.send(:primary_key_lookup, ((fk = opts[:key]).is_a?(Array) ? fk.map{|c| send(c)} : send(fk)))
  else
    super
  end
end