Created
September 14, 2008 18:51
-
-
Save be9/10747 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 | |
require 'rubygems' | |
require 'dm-core' | |
require 'dm-is-list' | |
require 'pp' | |
class Participation | |
include DataMapper::Resource | |
property :id, Serial | |
belongs_to :event | |
belongs_to :client | |
is :list, :scope => [:event_id] | |
end | |
class Event | |
include DataMapper::Resource | |
property :id, Serial | |
property :name, String | |
has n, :participations, :order => [:position.asc] | |
has n, :clients, :through => :participations | |
end | |
class Client | |
include DataMapper::Resource | |
property :id, Serial | |
property :name, String | |
has n, :participations | |
has n, :events, :through => :participations | |
end | |
#DataMapper.logger.set_log($stderr, :debug) | |
DataMapper.setup(:default, 'sqlite3::memory:') | |
DataMapper.auto_migrate!() | |
e1 = Event.create(:name => 'Event1') | |
e2 = Event.create(:name => 'Event2') | |
c1 = Client.create(:name => 'Client1') | |
c2 = Client.create(:name => 'Client2') | |
p1 = Participation.create(:client => c1, :event => e1) | |
p2 = Participation.create(:client => c2, :event => e1) | |
p3 = Participation.create(:client => c1, :event => e2) | |
pp e1.clients | |
#pp e2.clients | |
#puts p1.position ,p2.position, p3.position | |
p2.move :highest | |
e1.reload | |
e1.clients.reload | |
pp e1.clients | |
pp e1.participations.map { |p| p.client } | |
#p1.reload | |
#p2.reload | |
#p3.reload | |
#puts p1.position, p2.position, p3.position |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment