修改 authority 关联删除的问题

This commit is contained in:
pixel
2020-08-25 13:56:48 +08:00
parent cd708e3dd0
commit 50f962da44
3 changed files with 5 additions and 8 deletions
+4 -2
View File
@@ -87,9 +87,11 @@ func DeleteAuthority(auth *model.SysAuthority) (err error) {
if !notHas {
return errors.New("此角色存在子角色不允许删除")
}
db := global.GVA_DB.Preload("SysBaseMenus").Where("authority_id = ?", auth.AuthorityId).First(auth).Unscoped().Delete(auth)
db := global.GVA_DB.Preload("SysBaseMenus").Where("authority_id = ?", auth.AuthorityId).First(auth)
err = db.Unscoped().Delete(auth).Error
if len(auth.SysBaseMenus) > 0 {
err = db.Association("SysBaseMenus").Delete(auth.SysBaseMenus)
err = global.GVA_DB.Model(auth).Association("SysBaseMenus").Delete(auth.SysBaseMenus)
//err = db.Association("SysBaseMenus").Delete(&auth)
} else {
err = db.Error
}