Created
November 12, 2009 22:26
-
-
Save dkubb/233365 to your computer and use it in GitHub Desktop.
This file contains 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 User | |
include DataMapper::Resource | |
property :id, Serial | |
has n, :ownerships, :inverse => :owner | |
has n, :games, :through => :ownerships | |
end | |
class Game | |
include DataMapper::Resource | |
property :id, Serial | |
has n, :ownerships | |
has n, :owners, 'User', :through => :ownerships # FIXME: explicit "User" will not always be necessary | |
end | |
class Ownership | |
include DataMapper::Resource | |
property :game_id, Integer, :key => true, :min => 1 | |
property :owner_id, Integer, :key => true, :min => 1 | |
belongs_to :game | |
belongs_to :owner, 'User' | |
end | |
DataMapper.auto_migrate! | |
puts '-' * 80 | |
User.create(:games => [ {} ]) | |
puts '-' * 80 | |
Game.create(:owners => [ {} ]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment