Methods

Class/Module Index [+]

Quicksearch

Sequel::Plugins::IdentityMap

The identity_map plugin allows the user to create temporary identity maps via the with_identity_map method, which takes a block. Inside the block, objects have a 1-1 correspondence with rows in the database.

For example, the following is true, and wouldn't be true if you weren't using the identity map:

Sequel::Model.with_identity_map do
  Album.filter{(id > 0) & (id < 2)}.first.object_id == Album.first(:id=>1).object_id
end

In addition to providing a 1-1 correspondence, the identity_map plugin also provides a cached looked up of records in two cases:

If the object you are looking up, using one of those two methods, is already in the identity map, the record is returned without a database query being issued.

Identity maps are thread-local and only persist for the duration of the block, so they should only be considered as a possible performance enhancer.

The identity_map plugin is not compatible with the eager loading in the rcte_tree plugin.

Usage:

# Use an identity map that will affect all model classes (called before loading subclasses)
Sequel::Model.plugin :identity_map

# Use an identity map just for the Album class
Album.plugin :identity_map
# would need to do Album.with_identity_map{} to use the identity map

Public Class Methods

apply(mod) click to toggle source
# File lib/sequel/plugins/identity_map.rb, line 36
def self.apply(mod)
  Sequel::Deprecation.deprecate('The identity_map plugin', 'Please stop loading it') unless defined?(SEQUEL_EXTENSIONS_NO_DEPRECATION_WARNING)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.