Skip to content

Instantly share code, notes, and snippets.

@yannick
Created July 12, 2010 11:01
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 yannick/472363 to your computer and use it in GitHub Desktop.
Save yannick/472363 to your computer and use it in GitHub Desktop.
require 'datamapper'
class Person
include DataMapper::Resource
property :id, Serial
property :name, String
has n, :managers, 'Person', :through => Resource
has n, :managees, 'Person', :through => :managers, :child_key => [:person_id]
end
DataMapper.setup :default, 'sqlite3::memory:'
DataMapper.auto_migrate!
user1 = Person.create(:name => 'Dan Kubb')
user2 = Person.create(:name => 'John Doe', :managers => [ user1 ])
user1.save!
user2.save!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment