beego 如何获取foreign key字段?



 type Article struct {
    Id    int64
    Title string
    Content    string `orm:"size(5000)"`
    Author     string
    Source     string
    Keywords   string
    Overview   string
    Attachment string
    Created    time.Time `orm:"index"`
    Updated    time.Time `orm:"index"`
    Type       int64
    Category   *Category `orm:"rel(fk)"`
}

type Category struct {
    Id      int64
    Name    string
    Created time.Time `orm:"index"`
    Updated time.Time `orm:"index"`
}

各位大神们怎么搞啊?
如图beego orm增加表关系,article 的 foreign key为category。这样会在article表里自动增加一个category_id的字段。那么问题来了,比如我想修改这个article表里的category_id的字段的值,改怎么该?怎么才能获取这个category_id字段啊? 比如其他字段都是article.Title article.Author等。

beego go

我勒个去去 9 years, 11 months ago

Your Answer