Skip to content

Instantly share code, notes, and snippets.

@slaskis
Created February 15, 2010 14:09
Show Gist options
  • Save slaskis/304674 to your computer and use it in GitHub Desktop.
Save slaskis/304674 to your computer and use it in GitHub Desktop.
require "rubygems"
require "dm-core"
require "pp"
DataMapper::Logger.new(STDOUT,:debug)
DataMapper.setup(:default, "sqlite3://#{Dir.pwd}/bula.db")
class Entry
include DataMapper::Resource
has n, :related
property :id, Serial
property :title, String, :length => 255, :index => true
property :class_name, Discriminator
end
class Person < Entry
property :name, String, :length => 255, :index => true
property :email, String, :length => 255, :index => true
end
class Media < Entry
property :id, Serial
property :url, String, :length => 1024
end
class Work < Entry
property :body, Text
end
class Related
include DataMapper::Resource
belongs_to :to, :model => Entry
has 1, :entry, :through => Resource
property :id, Serial
property :title, String, :length => 255
property :created_at, DateTime
property :updated_at, DateTime
end
DataMapper.auto_migrate!
m = Media.create( :url => "ABC" )
p = Person.create( :email => "ABC" )
w = Work.create( :body => "DEF" )
w.related.create( :title => "A" , :entry => m )
w.related.create( :title => "B" , :entry => p )
w.save
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment