duanjia4817 2019-09-16 15:20
浏览 23

关联在golang或sql中有很多

I am trying to create the data has many to many in gorm, but I got null result after it created thought I already make right Request same like the structs each others associations

it doesn't error but the result not like I hope

Clone struct {
    ID         uint         `gorm:"auto_increment;primary_key" json:"id"`
    UpdatedAt  time.Time    `gorm:"type:timestamp" default:"CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP" json:"updated_at"`
    PersonID   uint         `json:"person_id"`
    Person     *Person      `gorm:"foreignkey:PersonID;association_foreignkey:id" json:"person"`
    Types      []*ColorType  `gorm:"foreignkey:CloneID;association_foreignkey:id" json:"types"`
    Skills     []*CloneSkill `gorm:"foreignkey:CloneID;association_foreignkey:id" json:"skills"`
    ProviderID uint         `gorm:"REFERENCES providers;index" json:"provider_id"`
}

here my clone skill and type sturct :

    CloneType struct {
        ID           uint   `gorm:"auto_increment;primary_key" json:"id"`
        CloneTypeName string `gorm:"size:20" json:"maid_type"`
        CLoneID       uint   `gorm:"REFERENCES clones;index" json:"clone_id"`
    }

    CloneSkill struct {
        ID     uint   `gorm:"auto_increment;primary_key" json:"id"`
        Skill  string `gorm:"size:30" json:"skill"`
        CloneID uint   `gorm:"REFERENCES clones;index" json:"clone_id"`
    }

let me explain, I have Person that has role : "clone, client, provider" provider has many clones and clone has one provider,

if it SQL it means

Clone has many types and skills

person is the main entity for my case, I am here to request to create clones when provider request it , my request body is very similar like those Clone stuct,

but after I create it, it only create Person, Provider and Clone, it doesn't create entity of CloneType and CloneSkills

do I miss something or my associates are wrong ?

if you are from SQL based, how do u design for those entity

Person has role clone, provider, client Clone has providers provider has many clones clone has many types clone has many skill

in sql my database like this

Person : name, email, 
Clone : person_id, provider_id
Provider: person_id 
Clone_Skill : skill, clone_id 
Clone_Type: type, clone_id
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 划分vlan后不通了
    • ¥15 GDI处理通道视频时总是带有白色锯齿
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大
    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大