Skip to content

Instantly share code, notes, and snippets.

@arbales
Forked from dkubb/standalone_example.rb
Created November 9, 2009 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arbales/230255 to your computer and use it in GitHub Desktop.
Save arbales/230255 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
property :name, String
has n, :mailers
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
belongs_to :person
has n, :mailer_people
has n, :people, :through => :mailer_people
end
DataMapper.auto_migrate!
p = Person.new(:name => 'Austin')
p.save
p = Person.new(:name => 'Jon')
p.save
p = Person.new(:name => 'Jon')
p.save
Mailer.create(:people => Person.all(:name => 'Jon'), :person => Person.first())
Mailer.create(:people => Person.all(:name => 'Jon'), :person => Person.first())
p Mailer.first().people
p Mailer.first().person # Austin
p Mailer.get(2).person # Jon, WAht!?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment