多对多关系时,使用save()方法去更新数据时,会在关联表中新增一条数据,期望是更新
表结构:
type DnsPreplanAtom struct {
Model
Name string json:"name"
OriginValue string json:"origin_value"
TargetValue string json:"target_value"
Domain string json:"domain"
LineName string json:"line_name"
LineId int json:"line_id"
Updator string json:"updator"
ProductTreeId string json:"product_tree_id"
ProductTreeName string json:"product_tree_name"
Status int json:"status"
ExecuteStatus int json:"execute_status"
DnsPreplanService []DnsPreplanService json:"dns_preplan_services" gorm:"many2many:dns_preplan_service_atom_rel"
}
type DnsPreplanService struct {
Model
Name string json:"name"
Desc string json:"desc"
Updator string json:"updator"
Status int json:"status" gorm:"default:1"
ExecuteStatus int json:"execute_status" gorm:"default:0"
ProductTreeId string json:"product_tree_id"
ProductTreeName string json:"product_tree_name"
DnsPreplanAtom []DnsPreplanAtom json:"dns_preplan_atoms" gorm:"many2many:dns_preplan_service_atom_rel;"
}
想请教下如果期望更新的话,应该怎么做? 当前使用的gorm 是v2版本
Comment From: github-actions[bot]
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨