我有一个关联设置,其中Track
可以属于多个Releases
到ReleaseTracks
:
class Release < ApplicationRecord
has_many :release_tracks, dependent: :destroy
has_many :tracks, through: :release_tracks
end
class ReleaseTrack < ApplicationRecord
# disc, side, number
belongs_to :release
belongs_to :track
belongs_to :album
end
class Track < ApplicationRecord
has_many :release_tracks, dependent: :destroy
has_many :releases, through: :release_tracks
validates_uniqueness_of :name, scope: [:release_id, :album_id]
end
如您所见,ReleaseTrack
有三个属性disc, side, number
,可以正确识别任何特定版本的曲目的正确位置。我想知道在发布表单中创建新曲目的例子,我怎么能保存这三个属性呢?