fix nested refs not being recognized as "populated" during serialization

This commit is contained in:
☙◦ The Tablet ❀ GamerGirlandCo ◦❧ 2025-04-10 16:47:57 -04:00
parent 0ebe3a2a3a
commit 378b5d756a
Signed by: tablet
GPG Key ID: 924A5F6AF051E87C
2 changed files with 13 additions and 0 deletions

View File

@ -84,6 +84,7 @@ type IDocument interface {
markPopulated(field string) markPopulated(field string)
markDepopulated(field string) markDepopulated(field string)
newPopulationMap() newPopulationMap()
getPopulated() map[string]bool
getRaw() any getRaw() any
setRaw(raw any) setRaw(raw any)
} }

View File

@ -84,6 +84,14 @@ func serializeIDs(input interface{}, isJson bool, populated map[string]bool, par
break break
} }
} }
if iidoc, ok := input.(IDocument); ok && !ip {
for k1, v1 := range iidoc.getPopulated() {
if k1 == descent || k1 == ft.Name {
ip = v1
break
}
}
}
if terr == nil { if terr == nil {
ifc, ok := fv.Interface().(HasID) ifc, ok := fv.Interface().(HasID)
if fv.Kind() == reflect.Slice { if fv.Kind() == reflect.Slice {
@ -316,6 +324,10 @@ func (d *Document) newPopulationMap() {
} }
} }
func (d *Document) getPopulated() map[string]bool {
return d.populatedFields
}
func (d *Document) setRaw(raw any) { func (d *Document) setRaw(raw any) {
d.raw = raw d.raw = raw
} }