Skip to content

Instantly share code, notes, and snippets.

@tpitale
Created August 12, 2010 18:27
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 tpitale/e9b99a4ce0d49e4dc93f to your computer and use it in GitHub Desktop.
Save tpitale/e9b99a4ce0d49e4dc93f to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'dm-core'
require 'dm-postgres-adapter'
require 'dm-migrations'
require 'dm-validations'
require 'dm-transactions'
DataMapper::Logger.new($stdout, :debug)
DataMapper.setup(:default, 'postgres://user@localhost/nested_attrs_test')
class User
include DataMapper::Resource
property :id, Serial
property :email, String
has n, :handles
end
class Handle
include DataMapper::Resource
property :id, Serial
property :name, String, :required => true
belongs_to :user
end
DataMapper.finalize
DataMapper.auto_migrate!
u = User.new(:email => 'user@example.com', :handles => [Handle.new])
puts u.save # => false, but user is created, handle is not
puts u.handles.last.errors.inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment