1
我有两个表如何插入一条记录到现有的有许多表格姆
type Podcast struct {
Id int
Title string
RssUrl string `sql:"unique_index"`
Episodes []Episode
}
type Episode struct {
Id int
PodcastID int
Title string
Url string `sql:"unique_index"`
Downloaded bool
}
我知道如何插入事件到一个新的播客,像这样。
podcast := Podcast{
Title: "My Podcast",
RssUrl: "http://example.com/feed/",
Url: "http://www.example.com",
Episodes: []Episode{{
Title: "Episode One Point Oh!",
Url: "http://www.example.com/one-point-oh",
Downloaded: false,
}},
}
db.Create(&podcast)
我该如何去添加剧集到稍后已经存在的播客?