首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在结构中设置一个特定的键作为beego orm中的外键?

如何在结构中设置一个特定的键作为beego orm中的外键?
EN

Stack Overflow用户
提问于 2020-04-17 17:35:08
回答 1查看 116关注 0票数 0

我想将Coins结构的地址设置为Accounts结构的外键地址,如何在beego orm中设置?

代码语言:javascript
运行
复制
type Coins struct {
    Id        int       `orm:"auto"`
    Address   string    `orm:"rel(fk);on_delete(cascade);on_update(cascade);index" json:"address"`
    Symbol    string    `json:"symbol"`
    Amount    float64   `orm:"digits(64);decimals(6)" json:"amount"`
    CreatedAt time.Time `orm:"auto_now_add;type(datetime)"`
    UpdatedAt time.Time `orm:"auto_now_add;type(datetime)"`
}

type Accounts struct {
    Id                       int       `orm:"auto"`
    Address                  string    `orm:"index;unique" json:"address"`
    Type                     string    `json:"type"`
}
EN

Stack Overflow用户

发布于 2020-04-17 19:37:52

看,如果这行得通:

代码语言:javascript
运行
复制
type Coins struct {
    Id        int       `orm:"auto"`
    Accouts   *Accounts `orm:"rel(fk)"`
    Address   string `orm:"pk;auto;on_delete(cascade);on_update(cascade);index" json:"address"`
    Symbol    string    `json:"symbol"`
    Amount    float64   `orm:"digits(64);decimals(6)" json:"amount"`
    CreatedAt time.Time `orm:"auto_now_add;type(datetime)"`
    UpdatedAt time.Time `orm:"auto_now_add;type(datetime)"`
}

type Accounts struct {
    Id                       int       `orm:"pk;auto"`
    Address                  string    `orm:"index;unique" json:"address"`
    Type                     string    `json:"type"`
}
票数 1
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61268327

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档