Skip to content

Instantly share code, notes, and snippets.

@be9
Created September 14, 2008 18:51
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 be9/10747 to your computer and use it in GitHub Desktop.
Save be9/10747 to your computer and use it in GitHub Desktop.
#!/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