0
用的has_many保存模型,我爲有模型,如軌如何通過關聯
// Contains the details of Parties (Users)
class Party < ActiveRecord::Base
has_many :party_races
has_many :races, :through=>:party_races
end
// Contains the party_id and race_id mappings
class PartyRace < ActiveRecord::Base
belongs_to :party
belongs_to :race
end
// Contains list of races like Asian,American,etc..
class Race < ActiveRecord::Base
has_many :party_races
has_many :parties, :through => :party_races
end
現在,讓我們說我創建黨 party_instance = Party.new
的實例,我怎麼加多個種族到party_instance
並保存到數據庫?