This regards the ruby ORM library DataMapper.
This wiki describes how to use the in_memory adapter for DataMapper. The proper database adapters saves an incrementing, unique id on each model instance - in_memory doesn't seem to do that as shown by the following snippet:
require 'rubygems'
require 'dm-core'
DataMapper.setup(:in_memory, :adapter => 'in_memory')
class Foo
include DataMapper::Resource
def self.default_repository_name;:in_memory;end
def self.auto_migrate_down!(rep);end
def self.auto_migrate_up!(rep);end
def self.auto_upgrade!(rep);end
property :id, Serial
property :name, Text
end
f = Foo.new
f.name = "foo"
f.save
puts f.inspect
The results of the inspect is:
#<Foo id=nil name="foo">
Had I used another adapter to connect to, for instance, a sqlite database id would've been set to '1'.
I would like to refer to my models via id, because I can't guarantee uniqueness on other attribuets. Is there a way of making the in_memory adapter save an incrementing, unique id attribute for its models?