2012-10-15 165 views
0

在我的模型中,遊戲和用戶之間存在多對多的關係。我怎樣才能找到涉及給定玩家的所有遊戲?查找涉及玩家的遊戲

我試圖Game.all(Game.users.include?(u))但有一個NoMethodErrorinclude?


這裏是我的模型每http://datamapper.org/docs/associations.html

class User 
    include DataMapper::Resource 

    property :id,   Serial 

    has n, :games, :through => Resource 
end 

class Game 
    include DataMapper::Resource 

    property :id,   Serial 

    has n, :users, :through => Resource 
end 

回答

1

假設你有一個用戶u,那麼你想要什麼爲u的一個實例。 games.all。每個用戶都有一套遊戲。我認爲這是他們正在玩的遊戲。