-
-
Save tpitale/e9b99a4ce0d49e4dc93f to your computer and use it in GitHub Desktop.
This file contains 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' | |
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