Skip to content

Instantly share code, notes, and snippets.

@pdlug pdlug/gist:31202
Created Dec 2, 2008

Embed
What would you like to do?
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
You can’t perform that action at this time.