Skip to content

Instantly share code, notes, and snippets.

Created June 24, 2010 04:03
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 anonymous/450961 to your computer and use it in GitHub Desktop.
Save anonymous/450961 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'dm-core'
require 'dm-types'
DataMapper.setup(:default, "abstract::")
class Person
include DataMapper::Resource
property :id, Serial
property :name, String
property :status, Enum[:registered, :guest], :default => :guest
end
class Post
include DataMapper::Resource
property :id, Serial
belongs_to :person
end
pete = Person.new(:name => 'pete', :status => :registered) # => <Person @id=nil @name="pete" @status=:registered>
post = Post.new(:person => pete) # => <Post @id=nil @person_id=nil>
pete # => <Person @id=nil @name="pete" @status=1>
post.person # => <Person @id=nil @name="pete" @status=nil>
pete # => <Person @id=nil @name="pete" @status=nil>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment