Skip to content

Commit 4cd55f6

Browse files
committed
Add handling for embedded structs
1 parent 8b2a8a9 commit 4cd55f6

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

schema/field.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ func (field *Field) setupValuerAndSetter() {
896896
if !reflectV.IsValid() {
897897
field.ReflectValueOf(ctx, value).Set(reflect.New(field.FieldType).Elem())
898898
} else if reflectV.Kind() == reflect.Ptr && reflectV.IsNil() {
899-
if field.FieldType.Elem().Kind() == reflect.Array {
899+
if field.FieldType.Elem().Kind() == reflect.Array && field.OwnerSchema == nil {
900900
field.ReflectValueOf(ctx, value).Set(reflectV)
901901
}
902902
} else if reflectV.Type().AssignableTo(field.FieldType) {

tests/embedded_struct_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"testing"
99
"time"
1010

11+
"github.com/google/uuid"
1112
"gorm.io/gorm"
1213
. "gorm.io/gorm/utils/tests"
1314
)
@@ -114,6 +115,7 @@ func TestEmbeddedPointerTypeStruct(t *testing.T) {
114115
ContentPtr *Content
115116
Birthday time.Time
116117
BirthdayPtr *time.Time
118+
AuthorUUID *uuid.UUID
117119
}
118120

119121
type HNPost struct {

0 commit comments

Comments
 (0)