Tag: inverse

Rails :: inverse_of和Association扩展

我有以下设置 class Player :player do def in_hand find_all_by_location(‘hand’) end end end class Card :cards end 这意味着以下工作: p = Player.find(:first) c = p.cards[0] p.score # => 2 c.player.score # => 2 p.score += 1 c.player.score # => 3 c.player.score += 2 p.score # => 5 但以下行为方式不同: p = Player.find(:first) c = p.cards.in_hand[0] p.score # => 2 […]