Module: Sequel::Plugins::ManyToOnePkLookup

Defined in:
lib/sequel/plugins/many_to_one_pk_lookup.rb

Overview

This is a fairly simple plugin that modifies the internal association loading logic for many_to_one associations to use a simple primary key lookup on the associated class, which is generally faster as it uses mostly static SQL. Additional, if the associated class is caching primary key lookups, you get the benefit of a cached lookup.

This plugin is generally not as fast as the prepared_statements_associations plugin in the case where the model is not caching primary key lookups, however, it is probably significantly faster if the model is caching primary key lookups. If the prepared_statements_associations plugin has been loaded first, this plugin will only use the primary key lookup code if the associated model is caching primary key lookups.

This plugin attempts to determine cases where the primary key lookup would have different results than the regular lookup, and use the regular lookup in that case, but it cannot handle all situations correctly, which is why it is not Sequel’s default behavior.

You can disable primary key lookups on a per association basis with this plugin using the :many_to_one_pk_lookup=>false association option.

Usage:

# Make all model subclass instances use primary key lookups for many_to_one
# association loading
Sequel::Model.plugin :many_to_one_pk_lookup

# Do so for just the album class.
Album.plugin :many_to_one_pk_lookup

Defined Under Namespace

Modules: InstanceMethods