Hello guys

I'm trying to work with a lot of through associations, but they seem to fail. 
Here's an example incl. test:
Anyone got an idea how to fix this?

require 'rubygems'
require 'bacon'
require 'dm-core'
File.unlink('model.log') rescue
DataMapper::Logger.new('model.log', :debug)
DataMapper.setup(:default, 'sqlite3::memory:')
dir = File.dirname(__FILE__)
class League
  include DataMapper::Resource
  property :id, Serial
  property :name, String
  has n, :league_membership
  has n, :player, :through => :league_membership
end

class LeagueMembership
  include DataMapper::Resource
  property :id, Serial
  belongs_to :player
  belongs_to :league
  has n, :league_event
end

class Player
  include DataMapper::Resource
  property :id, Serial
  property :name, String
  has n, :league_membership
  has n, :league, :through => :league_membership
end

class LeagueEvent
  include DataMapper::Resource
  property :id, Serial
  property :reason, Text
  belongs_to :league_membership
  belongs_to :player, :through => :league_membership
  belongs_to :league, :through => :league_membership
end

DataMapper.auto_migrate!

describe 'League' do
  before do
    @league = League.create :name => "foo"
    @player = Player.create :name => "bar"
    @mem = LeagueMembership.create(:player => @player, :league => @league)
    @event = LeagueEvent.create(:reason => "win", :league_membership => @mem)
    @event.reload
  end
  it 'should query with through assoc' do
    @mem.league.should.equal @league
    @mem.player.should.equal @player
    @event.player.should.equal @player
    @event.league.should.equal @league
  end
end

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/datamapper?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to