Skip to content

Commit

Permalink
Add handling for embedded structs
Browse files Browse the repository at this point in the history
  • Loading branch information
omkar-foss committed Jul 10, 2024
1 parent 8b2a8a9 commit 4cd55f6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion schema/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ func (field *Field) setupValuerAndSetter() {
if !reflectV.IsValid() {
field.ReflectValueOf(ctx, value).Set(reflect.New(field.FieldType).Elem())
} else if reflectV.Kind() == reflect.Ptr && reflectV.IsNil() {
if field.FieldType.Elem().Kind() == reflect.Array {
if field.FieldType.Elem().Kind() == reflect.Array && field.OwnerSchema == nil {
field.ReflectValueOf(ctx, value).Set(reflectV)
}
} else if reflectV.Type().AssignableTo(field.FieldType) {
Expand Down
2 changes: 2 additions & 0 deletions tests/embedded_struct_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"testing"
"time"

"github.com/google/uuid"
"gorm.io/gorm"
. "gorm.io/gorm/utils/tests"
)
Expand Down Expand Up @@ -114,6 +115,7 @@ func TestEmbeddedPointerTypeStruct(t *testing.T) {
ContentPtr *Content
Birthday time.Time
BirthdayPtr *time.Time
AuthorUUID *uuid.UUID
}

type HNPost struct {
Expand Down

0 comments on commit 4cd55f6

Please sign in to comment.