-
-
Save dkubb/230179 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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