enhancement from #1552

This commit is contained in:
John Guo
2022-02-15 23:55:05 +08:00
parent 6ffdff7095
commit 86b90ed4b6

View File

@ -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 {