次のモデルで:
package models
import "github.com/astaxie/beego/orm"
type Movie struct {
Id int `orm:"pk; auto; column(id)"; form: "-"`
Title string `orm:"unique; column(title)"; form: "title, text, title:`
Plot string `orm:"column(plot)"; form: "plot, text, plot:"`
ImdbID string `orm:"column(imdb_id)"; form: "imdb_id, text, imdb_id:"`
Actors string `orm:"column(actors)"; form: "actors, text, actors:"`
Runtime string `orm:"column(runtime)"; form: "runtime, text, runtime:"`
Year string `orm:"column(year)"; form: "year, text, year:"`
Genre *Genre `orm:"rel(fk); on_delete(do_nothing)"`
Cover string `orm:"column(cover)"; form: "cover, text, cover:"`
Status int `orm:"column(status)"; form: "status, int, status:"`
}
func (a *Movie) TableName() string {
return "app_movie"
}
func init() {
orm.RegisterModel(new(Movie))
}
参照したいのは、次のようなジャンル モデルです。
package models
import "github.com/astaxie/beego/orm"
type Genre struct {
Id int `orm:"pk; auto; column(id)"; form: "-"`
Title string `orm:"unique; column(title)"; form: "title, text, title:`
Status int `orm:"column(status)"; form: "status, int, status:"`
}
func (a *Genre) TableName() string {
return "app_genre"
}
func init() {
orm.RegisterModel(new(Genre))
}
詳細については、データを含む sqlite db に移動します (DB が最初)。
コントローラーで、映画のリストを繰り返し処理して出力します: movie.Genre.Title ですが、空です。movie.Genre で見ると、次のようになります: {3 0}
タイトルとIDを取得するにはどうすればよいですか? または。私は何を間違っていますか?
ご協力いただきありがとうございます!