module Sequel::Plugins::IdentityMap::InstanceMethods

Public Instance Methods

delete() click to toggle source

Remove instances from the identity map cache if they are deleted.

Calls superclass method
# File lib/sequel/plugins/identity_map.rb, line 213
def delete
  super
  if (idm = model.identity_map) && (k = model.identity_map_key(pk))
    idm.delete(k)
  end
  self
end
merge_db_update(row) click to toggle source

Merge the current values into the values provided in the row, ensuring that current values are not overridden by new values.

# File lib/sequel/plugins/identity_map.rb, line 223
def merge_db_update(row)
  @values = row.merge(@values)
end

Private Instance Methods

_associated_object_pk(fk) click to toggle source

The primary keys values of the associated object, given the foreign key columns(s).

# File lib/sequel/plugins/identity_map.rb, line 231
def _associated_object_pk(fk)
  fk.is_a?(Array) ? fk.map{|c| send(c)} : send(fk)
end
_load_associated_object(opts, dynamic_opts) click to toggle source

If the association is a many_to_one and it has a :key option and the key option has a value and the association uses the primary key of the associated class as the :primary_key option, check the identity map for the associated object and return it if present.

Calls superclass method
# File lib/sequel/plugins/identity_map.rb, line 239
def _load_associated_object(opts, dynamic_opts)
  klass = opts.associated_class
  cache_lookup = opts.fetch(:idm_cache_lookup) do 
    opts[:idm_cache_lookup] = klass.respond_to?(:identity_map) &&
      opts[:type] == :many_to_one &&
      opts[:key] &&
      opts.primary_key == klass.primary_key
  end
  if cache_lookup &&
    !dynamic_opts[:callback] &&
    (idm = klass.identity_map) &&
    (k = klass.identity_map_key(_associated_object_pk(opts[:key]))) && 
    (o = idm[k])
    o
  else
    super
  end
end