feat: optimize ignore fields in orm (#5015)

This commit is contained in:
Kevin Wan
2025-07-18 20:36:28 +08:00
committed by GitHub
parent cc79e3d842
commit ff890628b0
2 changed files with 187 additions and 83 deletions

View File

@@ -9,7 +9,10 @@ import (
"github.com/zeromicro/go-zero/core/mapping"
)
const tagName = "db"
const (
tagIgnore = "-"
tagName = "db"
)
var (
// ErrNotMatchDestination is an error that indicates not matching destination to scan.
@@ -269,21 +272,20 @@ func unwrapFields(v reflect.Value) []reflect.Value {
continue
}
childType := indirect.Type().Field(i)
if parseTagName(childType) == tagIgnore {
continue
}
if child.Kind() == reflect.Ptr && child.IsNil() {
baseValueType := mapping.Deref(child.Type())
child.Set(reflect.New(baseValueType))
}
child = reflect.Indirect(child)
childType := indirect.Type().Field(i)
if child.Kind() == reflect.Struct && childType.Anonymous {
fields = append(fields, unwrapFields(child)...)
} else {
key := parseTagName(childType)
if key == "-" {
continue
}
fields = append(fields, child)
}
}