Skip to content

Instantly share code, notes, and snippets.

@drio
Created July 25, 2009 03:18
Show Gist options
  • Save drio/154673 to your computer and use it in GitHub Desktop.
Save drio/154673 to your computer and use it in GitHub Desktop.
require 'dm-core'
require 'dm-validations'
require 'dm-timestamps'
DataMapper.setup(:default, "sqlite3://#{Dir.pwd}/mydb.sqlite3")
class Post
include DataMapper::Resource
has n, :comments
# The Serial type provides auto-incrementing primary keys
property :id, Serial
# ...or pass a :key option for a user-set key like the name of a user:
property :name, String, :key => true
end
class Comment
include DataMapper::Resource
belongs_to :post
property :id, Serial
property :email, String
end
DataMapper.auto_upgrade!
def create_post(rname)
p = Post.new({:name => rname})
p.save
end
def add_comment(p_id, pair_data)
#p = Post.first({:id =>1})
p = Post.get(1)
c = p.comments.build(pair_data)
c.save
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment