1
我的2種型號:使用構建不創建連接模型上的has_many:通過關聯
Class TeamHistory < ActiveRecord::Base
has_many :player_to_team_histories
has_many :players, through: :player_to_team_histories
belongs_to :team
end
Class Player < ActiveRecord::Base
has_many :player_to_team_histories
has_many :team_histories, through: :player_to_team_histories
end
我不能去使用@team_history.players.build
創建的player_to_team_histories
,但它正常工作與@team_history.players.create
>>team = Team.create
>>team_history = team.team_histories.create
>>player = team_history.players.create
>>player.team_histories.count
1
>>player2 = team_history.players.build
>>player2.team_histories.count
0
>>player2.save
>>player2.team_histories.count
0
複製粘貼錯誤。謝謝你的收穫。我剛剛從我的模型中複製不正確。同樣的問題仍然存在。 – 2012-08-09 23:34:49