From 378b5d756a6aa1e0f14e3877c932970cf483f325 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=98=99=E2=97=A6=20The=20Tablet=20=E2=9D=80=20GamerGirla?= =?UTF-8?q?ndCo=20=E2=97=A6=E2=9D=A7?= Date: Thu, 10 Apr 2025 16:47:57 -0400 Subject: [PATCH] fix nested refs not being recognized as "populated" during serialization --- document.go | 1 + document_internals.go | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/document.go b/document.go index addde2b..9994363 100644 --- a/document.go +++ b/document.go @@ -84,6 +84,7 @@ type IDocument interface { markPopulated(field string) markDepopulated(field string) newPopulationMap() + getPopulated() map[string]bool getRaw() any setRaw(raw any) } diff --git a/document_internals.go b/document_internals.go index 991827d..7dc6500 100644 --- a/document_internals.go +++ b/document_internals.go @@ -84,6 +84,14 @@ func serializeIDs(input interface{}, isJson bool, populated map[string]bool, par 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 { ifc, ok := fv.Interface().(HasID) 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) { d.raw = raw }