Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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