Browse Source

feat: get data from db after modify

0xJacky 1 year ago
parent
commit
68afb7e7e8
1 changed files with 9 additions and 1 deletions
  1. 9 1
      api/cosy/update.go

+ 9 - 1
api/cosy/update.go

@@ -5,7 +5,8 @@ import (
 	"github.com/0xJacky/Nginx-UI/model"
 	"github.com/gin-gonic/gin"
 	"gorm.io/gorm"
-	"net/http"
+    "gorm.io/gorm/clause"
+    "net/http"
 )
 
 func (c *Ctx[T]) SetNextHandler(handler gin.HandlerFunc) *Ctx[T] {
@@ -74,6 +75,13 @@ func (c *Ctx[T]) Modify() {
 		return
 	}
 
+	err = db.Preload(clause.Associations).First(&c.Model, id).Error
+
+	if err != nil {
+		c.AbortWithError(err)
+		return
+	}
+
 	if len(c.executedHookFunc) > 0 {
 		for _, v := range c.executedHookFunc {
 			v(c)