Datamapper has n relationship with multiple keys
Posted
by jing
on Stack Overflow
See other posts from Stack Overflow
or by jing
Published on 2010-03-23T12:45:29Z
Indexed on
2010/03/25
3:13 UTC
Read the original article
Hit count: 468
ruby
|datamapper
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
© Stack Overflow or respective owner