0

私のアプリでは、各ゲームには異なる役割を持つ2人のプレーヤーが関与しています。1つは猫を演じ、もう1つは犬を演じます。これをRubyのデータマッパーでどのように説明できますか?

ドキュメントには、プロパティの名前がクラスの名前と一致する例のみが示されています。これにより、クラスごとに1つの関連付けに制限されますhttp://datamapper.org/docs/associations.html

私のゲームには猫プレーヤーと犬プレーヤーが必要です。

4

1 に答える 1

1

あなたのリンクによるドキュメントに答えがあります。もっとよく読んでください。

class Player
  include DataMapper::Resource
end

class Game
  include DataMapper::Resource
  belongs_to :cat, 'Player'
  belongs_to :dog, 'Player'
end

更新:必要に応じて、Playerモデルでこれらの関連付けを使用できます

class Player
  include DataMapper::Resource
  has n, :cat_games, :child_key  => [ :cat_id ]
  has n, :dog_games, :child_key  => [ :dog_id ]
end
于 2012-10-16T06:14:43.700 に答える