0
두 번째 눈이 필요합니다. 두 플레이어 간의 경기를 만들면 Tournament.players는 빈 배열을 반환합니다.레일을 통해 has_many가 작동하지 않는 것 같습니다.
코드 당신은 이중 :through
관계를 가질 필요가
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
'Match' 모델을 추가 할 수 있습니까? – Zippie
예, 우리는'Match' 모델을보아야합니다 – OneChillDude
'Tournaments'와'Player'의 많은 플레이어가 일치하는 다형성을 고려할 수도 있습니다. – OneChillDude