From 86b90ed4b6caecdfed265718e08cd516bb538640 Mon Sep 17 00:00:00 2001 From: John Guo Date: Tue, 15 Feb 2022 23:55:05 +0800 Subject: [PATCH] enhancement from #1552 --- database/gdb/gdb_model_with.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/database/gdb/gdb_model_with.go b/database/gdb/gdb_model_with.go index a14955778..9d0e427a3 100644 --- a/database/gdb/gdb_model_with.go +++ b/database/gdb/gdb_model_with.go @@ -17,6 +17,7 @@ import ( "github.com/gogf/gf/v2/os/gstructs" "github.com/gogf/gf/v2/text/gregex" "github.com/gogf/gf/v2/text/gstr" + "github.com/gogf/gf/v2/util/gutil" ) // With creates and returns an ORM model based on metadata of given object. @@ -248,14 +249,16 @@ func (m *Model) doWithScanStructs(pointer interface{}) error { relatedTargetName, parsedTagOutput.With, ) } - + // If related value is empty, it does nothing but just returns. + if gutil.IsEmpty(relatedTargetValue) { + return nil + } // It automatically retrieves struct field names from current attribute struct/slice. if structType, err := gstructs.StructType(field.Value); err != nil { return err } else { fieldKeys = structType.FieldKeys() } - // Recursively with feature checks. model = m.db.With(field.Value) if m.withAll {