lib/praxis-mapper/identity_map.rb
def add_record(record)
      model = record.class
      record.identities.each do |identity, key|
        # FIXME: Should we be overwriting (possibly) a "nil" value from before?
        #        (due to that row not being found by a previous query)
        #        (That'd be odd since that means we tried to load that same identity)
        if (existing = @row_keys[model][identity][key])
          # FIXME: should merge record into existing to add any additional fields
          return existing
        end

        get_staged(model, identity).delete(key)
        @row_keys[model][identity][key] = record
      end

      @secondary_indexes[model].each do |key, indexed_values|
        val = if key.kind_of? Array
          key.collect { |k| record.send(k) }
        else
          record.send(key)
        end

        indexed_values[val] << record
      end

      record.identity_map = self
      @rows[model] << record
      record
    end
def add_record(record)
      model = record.class
      record.identities.each do |identity, key|
        # FIXME: Should we be overwriting (possibly) a "nil" value from before?
        #        (due to that row not being found by a previous query)
        #        (That'd be odd since that means we tried to load that same identity)
        if (existing = @row_keys[model][identity][key])
          # FIXME: should merge record into existing to add any additional fields
          return existing
        end

        get_staged(model, identity).delete(key)
        @row_keys[model][identity][key] = record
      end

      @secondary_indexes[model].each do |key, indexed_values|
        val = if key.kind_of? Array
          key.collect { |k| record.send(k) }
        else
          record.send(key)
        end

        indexed_values[val] << record
      end

      record.identity_map = self
      @rows[model] << record
      record
    end
return the record provided (if added to the identity map)
 or return the corresponding record if it was already present