From e4499162e4642b7d741f8bc45cfc11baa9fe149a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Szafra=C5=84ski?= Date: Wed, 16 Oct 2024 18:48:36 +0200 Subject: [PATCH] Add explanatory comment --- sqlx.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sqlx.go b/sqlx.go index c2f500c..dda1ce6 100644 --- a/sqlx.go +++ b/sqlx.go @@ -1035,6 +1035,9 @@ func fieldsByTraversal(v reflect.Value, traversals [][]int, values []interface{} } else if len(traversal) == 1 { values[i] = reflectx.FieldByIndexes(v, traversal).Addr().Interface() } else { + // reflectx.FieldByIndexes initializes pointer fields, including pointers to nested structs. + // Use optDest to delay it until the first non-NULL value is scanned into a field of a nested struct. + // That way we can support LEFT JOINs with optional nested structs. traversal := traversal values[i] = optDest(func() interface{} { return reflectx.FieldByIndexes(v, traversal).Addr().Interface()