Module | Sequel::Plugins::IdentityMap::ClassMethods
In: | lib/sequel/plugins/identity_map.rb

### Methods

identity_map identity_map_key load with_identity_map

### Public Instance methods

identity_map()

Returns the current thread-local identity map. Should be a hash if there is an active identity map, and nil otherwise.

[Source]

        # File lib/sequel/plugins/identity_map.rb, line 42
    42:         def identity_map
    43:           Thread.current[:sequel_identity_map]
    44:         end

identity_map_key(pk)

The identity map key for an object of the current class with the given pk. May not always be correct for a class which uses STI.

[Source]

        # File lib/sequel/plugins/identity_map.rb, line 48
    48:         def identity_map_key(pk)
    49:           "#{self}:#{pk ? Array(pk).join(',') : "nil:#{rand}"}"
    50:         end

load(row)

If the identity map is in use, check it for a current copy of the object. If a copy does not exist, create a new object and add it to the identity map. If a copy exists, add any values in the given row that aren‘t currently in the object to the object‘s values. This allows you to only request certain fields in an initial query, make modifications to some of those fields and request other, potentially overlapping fields in a new query, and not have the second query override fields you modified.

[Source]

        # File lib/sequel/plugins/identity_map.rb, line 59
    59:         def load(row)
    60:           return super unless idm = identity_map
    61:           if o = idm[identity_map_key(Array(primary_key).map{|x| row[x]})]
    62:             o.merge_db_update(row)
    63:           else
    64:             o = super
    65:             idm[identity_map_key(o.pk)] = o
    66:           end
    67:           o
    68:         end

with_identity_map() {|if identity_map| ...}

Take a block and inside that block use an identity map to ensure a 1-1 correspondence of objects to the database row they represent.

[Source]

        # File lib/sequel/plugins/identity_map.rb, line 72
    72:         def with_identity_map
    73:           return yield if identity_map
    74:           begin
    75:             self.identity_map = {}
    76:             yield
    77:           ensure
    78:             self.identity_map = nil
    79:           end
    80:         end

[Validate]