Created
December 2, 2008 18:04
-
-
Save pdlug/31202 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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