Skip to content

Instantly share code, notes, and snippets.

@pdlug
Created December 2, 2008 18:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pdlug/31202 to your computer and use it in GitHub Desktop.
Save pdlug/31202 to your computer and use it in GitHub Desktop.
require 'rubygems'
gem 'dm-core'
gem 'dm-types'
require 'dm-core'
require 'dm-types'
class User
include DataMapper::Resource
property :id, DM::UUID, :key => true, :unique_index => true, :default => lambda { ::UUID.random_create }
property :name, String
has n, :accounts
end
class Account
include DataMapper::Resource
property :id, DM::UUID, :key => true, :unique_index => true, :default => lambda { ::UUID.random_create }
property :code, String
belongs_to :user
end
DataMapper.setup(:default, 'sqlite3::memory:')
DataMapper.auto_migrate!
u = User.create(:name => 'test')
# this works
p Account.create(:user => u, :code => '123')
# this doesn't
p u.accounts.create(:code => '123')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment