mirror of
https://github.com/zeromicro/go-zero.git
synced 2026-05-11 00:40:00 +08:00
feat: optimize ignore fields in orm (#5015)
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user