修复键和值一样的情况会出现没有数据的情况
This commit is contained in:
parent
b9c8112a7c
commit
0e4226fd84
5
hook.go
5
hook.go
|
@ -2,6 +2,7 @@ package rest
|
|||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.nobla.cn/golang/rest/types"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
@ -133,7 +134,6 @@ func (hook *hookManager) afterSave(ctx context.Context, tx *gorm.DB, model any,
|
|||
cb(ctx, tx, model, diff)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (hook *hookManager) beforeDelete(ctx context.Context, tx *gorm.DB, model any) (err error) {
|
||||
|
@ -161,7 +161,6 @@ func (hook *hookManager) afterDelete(ctx context.Context, tx *gorm.DB, model any
|
|||
cb(ctx, tx, model)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (hook *hookManager) afterExport(ctx context.Context, filename string) {
|
||||
|
@ -174,7 +173,6 @@ func (hook *hookManager) afterExport(ctx context.Context, filename string) {
|
|||
cb(ctx, filename)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (hook *hookManager) afterImport(ctx context.Context, ret *types.ImportResult) {
|
||||
|
@ -187,7 +185,6 @@ func (hook *hookManager) afterImport(ctx context.Context, ret *types.ImportResul
|
|||
cb(ctx, ret)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (hook *hookManager) BeforeCreate(cb BeforeCreate) {
|
||||
|
|
17
rest.go
17
rest.go
|
@ -673,13 +673,12 @@ func ModelTypes[T any](ctx context.Context, db *gorm.DB, model any, domainName,
|
|||
} else {
|
||||
feed.Label = fmt.Sprint(s)
|
||||
}
|
||||
continue
|
||||
//这里不直接返回, 有可能key和value是同一个字段
|
||||
}
|
||||
if k == valueColumn {
|
||||
if p, ok := v.(T); ok {
|
||||
feed.Value = p
|
||||
}
|
||||
continue
|
||||
}
|
||||
}
|
||||
values = append(values, feed)
|
||||
|
@ -703,25 +702,23 @@ func ModelTiers[T comparable](ctx context.Context, db *gorm.DB, model any, domai
|
|||
for _, pairs := range result {
|
||||
feed := &types.TierValue[T]{}
|
||||
for k, v := range pairs {
|
||||
if k == parentColumn {
|
||||
if p, ok := v.(T); ok {
|
||||
feed.Parent = p
|
||||
}
|
||||
continue
|
||||
}
|
||||
if k == labelColumn {
|
||||
if s, ok := v.(string); ok {
|
||||
feed.Label = s
|
||||
} else {
|
||||
feed.Label = fmt.Sprint(s)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if k == valueColumn {
|
||||
if p, ok := v.(T); ok {
|
||||
feed.Value = p
|
||||
}
|
||||
continue
|
||||
}
|
||||
if k == parentColumn {
|
||||
if p, ok := v.(T); ok {
|
||||
feed.Parent = p
|
||||
}
|
||||
continue
|
||||
}
|
||||
}
|
||||
values = append(values, feed)
|
||||
|
|
Loading…
Reference in New Issue