add new function replace realtions
This commit is contained in:
@@ -387,3 +387,8 @@ func (dH *DBHandler) AddRelation(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)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user