第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

gorm Many2many 和關(guān)聯(lián)表中的附加字段

gorm Many2many 和關(guān)聯(lián)表中的附加字段

Go
翻閱古今 2023-07-17 14:48:32
我有一個多對多關(guān)聯(lián)(它用于返回 JSON)。它在模型中聲明:// models/school.gotype School struct {    ID                int      `gorm:"primary_key"`    Name              string `gorm:"not null"`    Accreditations    []Accreditation `gorm:"many2many:school_accreditation;"` }效果很好。我在 json 中返回了關(guān)聯(lián)。問題是我的school_accreditation表中有一個附加字段,但它未包含在響應中。我試圖為該協(xié)會聲明一個模型,就像這個答案中提出的那樣:// models/schoolAccreditation.gopackage modelsimport "time"// many to manytype SchoolAccreditation struct {    StartedAt time.Time `gorm:"not null"`}但到目前為止還不起作用。是否需要聲明一些額外的配置?還是要修改?
查看完整描述

1 回答

?
滄海一幻覺

TA貢獻1824條經(jīng)驗 獲得超5個贊

回答自己,我將鏈接模型中的字段添加為“忽略”,并且它有效,會自動從關(guān)聯(lián)表中檢索該列。


type Accreditation struct {

    // "accreditation" table

    ID          int `gorm:"primary_key"`

    Name        string

    Description string

    // "school_accreditation table", so the field is set as ignore with "-"

    EndAt       time.Time `gorm:"-"`

}


查看完整回答
反對 回復 2023-07-17
  • 1 回答
  • 0 關(guān)注
  • 158 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號