Created
October 30, 2009 12:09
-
-
Save MarkMT/222295 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
#!/usr/bin/env ruby -Ku | |
require 'rubygems' | |
require 'dm-core' | |
DataMapper::Logger.new($stdout, :debug) | |
DataMapper.setup(:default, 'mysql://localhost/testdb') | |
class User | |
include DataMapper::Resource | |
property :id, Serial | |
property :name, String | |
has 1, :address | |
end | |
class Address | |
include DataMapper::Resource | |
property :id, Serial | |
property :country, String | |
belongs_to :user | |
end | |
DataMapper.auto_migrate! | |
# Create a new user | |
u = User.new(:name => 'Bob') | |
p u.save # => true | |
# Read the record back from the db | |
u = User.first | |
# Assign a new address to the user | |
u.address ||= Address.new # => runtime error |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment