Skip to content

Instantly share code, notes, and snippets.

@protocarl
Created December 12, 2009 22:43
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 protocarl/4ac262e7236ea2408bea to your computer and use it in GitHub Desktop.
Save protocarl/4ac262e7236ea2408bea to your computer and use it in GitHub Desktop.
require 'rubygems'
gem 'dm-core', '0.10.2'
gem 'do_sqlite3', '0.10.0'
require 'dm-core'
class Author
include DataMapper::Resource
property :id, Serial
property :name, String
has n, :posts
end
class Post
include DataMapper::Resource
property :id, Serial
property :body, Text
property :author_id, String
belongs_to :author
end
DataMapper.setup(:default, 'sqlite3::memory:')
DataMapper.auto_migrate!
author = Author.create(:name => 'Alice', :id => '1')
author.posts.create(:body => 'Hello World')
# doesn't work becuase :author_id is a String
Post.first.author # => nil
Post.property :author_id, Integer
# works because :author_id is an Integer
Post.first.author # => #<Author @id=1 @name="Alice">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment