1 Commits

Author SHA1 Message Date
Adrian Zürcher
f5d1775943 add new function replace realtions 2026-02-16 21:43:53 +01:00

View File

@@ -387,3 +387,8 @@ func (dH *DBHandler) AddRelation(model, relation any, relationName string) error
func (dH *DBHandler) DeleteRelation(model, relation any, relationName string) error { func (dH *DBHandler) DeleteRelation(model, relation any, relationName string) error {
return dH.db.Model(model).Association(relationName).Delete(relation) return dH.db.Model(model).Association(relationName).Delete(relation)
} }
func (dH *DBHandler) ReplaceRelation(model any, relationName string, data any) error {
// .Replace() handles the "Delete missing / Add new" logic for you
return dH.db.Model(model).Association(relationName).Replace(data)
}