我需要对这个进行第二次观察。当我在两个玩家之间创建匹配时,Tournament.players 返回一个空数组。
代码
class Tournament < ActiveRecord::Base
has_many :player_matches
has_many :matches
has_many :players, :through => :player_matches
end
class PlayerMatch < ActiveRecord::Base
belongs_to :player
belongs_to :match
belongs_to :tournament
end
class Player < ActiveRecord::Base
has_many :player_matches
has_many :matches, :through => :player_matches
has_many :tournaments, :through => :player_matches
end