If the current association is a fairly 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.
# File lib/sequel/plugins/many_to_one_pk_lookup.rb, line 39 39: def _load_associated_object(opts, dynamic_opts) 40: klass = opts.associated_class 41: cache_lookup = opts.send(:cached_fetch, :many_to_one_pk_lookup) do 42: opts[:type] == :many_to_one && 43: opts[:key] && 44: opts.primary_key == klass.primary_key 45: end 46: if cache_lookup && 47: !dynamic_opts[:callback] && 48: (o = klass.send(:primary_key_lookup, ((fk = opts[:key]).is_a?(Array) ? fk.map{|c| send(c)} : send(fk)))) 49: o 50: else 51: super 52: end 53: end
Deal with the situation where the prepared_statements_associations plugin is loaded first, by using a primary key lookup for many_to_one associations if the associated class is using caching, and using the default code otherwise. This is done because the prepared_statements_associations code is probably faster than the primary key lookup this plugin uses if the model is not caching lookups, but probably slower if the model is caching lookups.
# File lib/sequel/plugins/many_to_one_pk_lookup.rb, line 61 61: def _load_associated_objects(opts, dynamic_opts={}) 62: if opts.can_have_associated_objects?(self) && opts[:type] == :many_to_one && opts.associated_class.respond_to?(:cache_get_pk) 63: _load_associated_object(opts, dynamic_opts) 64: else 65: super 66: end 67: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.