Skip to content

Instantly share code, notes, and snippets.

@ashgti
Created December 7, 2008 23:28
Show Gist options
  • Save ashgti/33282 to your computer and use it in GitHub Desktop.
Save ashgti/33282 to your computer and use it in GitHub Desktop.
require 'rubygems'
gem 'dm-core'
require 'dm-core'
require 'pp'
DataMapper.setup(:default, 'sqlite3::memory:')
DataMapper::Logger.new(STDOUT, :info)
DataObjects::Sqlite3.logger = DataObjects::Logger.new(STDOUT, 0)
class User
include DataMapper::Resource
property :id, Serial
property :name, String
property :value, BigDecimal
has n, :posts
before :save do
puts 'hello world'
true
end
end
class Post
include DataMapper::Resource
property :id, Serial
property :title, String
property :user_id, Integer
belongs_to :user
has n, :comments
end
class Comment
include DataMapper::Resource
property :id, Serial
property :from, String
property :content, String
belongs_to :post
end
DataMapper.auto_migrate!
pp User.all(User.posts.comments.from => "John")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment