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