Beego orm-关系不';行不通

Beego orm-关系不';行不通,go,orm,beego,Go,Orm,Beego,在以下模型中: 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

在以下模型中:

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,但其为空。如果我看电影,我会得到:{30}

如何获得标题和ID?或我做错了什么

谢谢你的帮助

num, err := qs
    .Limit(4)
    .Filter("status", true)
    .RelatedSel()
    .Exclude("useritem__userid", 1)
    .OrderBy("-id")
    .All(&movies)
一切正常。:)
.RelatedSel()


您如何进行查询?您在推荐中使用了RelatedSel?错误的代码格式,请查看答案部分。如果此查询存在/如果此处处于筛选(“状态”)状态,则将得到“1”,如果不存在,则得到“0”。我设置了限制(1)。(beego)
code
func AuthorizeUser(auth_token string)(bool,error){o:=orm.NewOrm()var users[]*User qs:=o.QueryTable(“User”)num,err:=qs.Limit(1).Filter(“auth_token”,auth_token).RelatedSel().OrderBy(“-id”)。所有(&用户)//如果err!=nil | num==0{返回false,err}返回true,则过滤匹配的auth token