-
-
Save protocarl/4ac262e7236ea2408bea 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' | |
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