Datamapper has n relationship with multiple keys
- by jing
I am working on a simple relationship with DataMapper, a ruby webapp to track games. A game belongs_to 4 players, and each player can have many games.
When I call player.games.size, I seem to be getting back a result of 0, for players that I know have games associated with them. I am currently able to pull the player associations off of game, but can't figure out why player.games is empty.
Do I need to define a parent_key on the has n association, or is there something else I'm missing?
class Game
belongs_to :t1_p1, :class_name => 'Player', :child_key => [:player1_id]
belongs_to :t1_p2, :class_name => 'Player', :child_key => [:player2_id]
belongs_to :t2_p1, :class_name => 'Player', :child_key => [:player3_id]
belongs_to :t2_p2, :class_name => 'Player', :child_key => [:player4_id]
...
end
class Player
has n, :games
...
end