Skip to content

Instantly share code, notes, and snippets.

@crguezl
Created October 22, 2014 11:28
Show Gist options
  • Save crguezl/5c0c088790418690763d to your computer and use it in GitHub Desktop.
Save crguezl/5c0c088790418690763d to your computer and use it in GitHub Desktop.
datamapper: simple associations
require 'data_mapper'
DataMapper::Logger.new($stdout, :debug)
DataMapper.setup(:default, "sqlite3://#{Dir.pwd}/example.db")
class Post
include DataMapper::Resource
property :id, Serial
property :text, Text
has n, :comments
end
class Comment
include DataMapper::Resource
property :id, Serial
property :text, Text
belongs_to :post # defaults to :required => true
end
DataMapper.finalize
require 'dm-migrations'
#DataMapper.auto_migrate!
DataMapper.auto_upgrade!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment