ポッドキャストからエピソードを取得しようとすると、invalid association []
. 私が間違っているのかわかりません。
package main
import (
"log"
"github.com/jinzhu/gorm"
_ "github.com/mattn/go-sqlite3"
)
type Podcast struct {
Id int
Title string
RssUrl string `sql:"unique_index"`
Url string
Episodes []Episode
}
type Episode struct {
Id int
PodcastID int `sql:"index"`
Title string
Url string `sql:"unique_index"`
Downloaded bool
}
func main() {
db, err := gorm.Open("sqlite3", "gorm.db")
if err != nil {
log.Fatal(err)
}
db.LogMode(true)
db.CreateTable(&Podcast{})
db.CreateTable(&Episode{})
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}},
}
var episodes []Episode
db.Model(&podcast).Related(&episodes)
}