Skip to content

Instantly share code, notes, and snippets.

@dkubb
Forked from arbales/standalone_example.rb
Created November 9, 2009 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dkubb/230179 to your computer and use it in GitHub Desktop.
Save dkubb/230179 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby -Ku
# encoding: utf-8
require 'rubygems'
require 'dm-core'
DataMapper::Logger.new($stdout, :debug)
DataMapper.setup(:default, 'sqlite3::memory:')
class Person
include DataMapper::Resource
property :id, Serial
has n, :mailer_people
has n, :conversations, 'Mailer', :through => :mailer_people, :via => :mailer
end
class MailerPerson
include DataMapper::Resource
property :person_id, Integer, :min => 1, :key => true
property :mailer_id, Integer, :min => 1, :key => true
belongs_to :person
belongs_to :mailer
end
class Mailer
include DataMapper::Resource
property :id, Serial
has n, :mailer_people
has n, :people, :through => :mailer_people
end
DataMapper.auto_migrate!
puts '-' * 80, 'Create Mailer, then Person, then intermediary'
Mailer.create(:people => [ {} ])
puts '-' * 80, 'Create Person, then Mailer, then intermediary'
Person.create(:conversations => [ {} ])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment