Returns error for invalid embedded field, close #3209

This commit is contained in:
Jinzhu 2020-07-29 10:23:14 +08:00
parent a140908839
commit 2cbdd29f26
1 changed files with 41 additions and 37 deletions

View File

@ -304,6 +304,7 @@ func (schema *Schema) ParseField(fieldStruct reflect.StructField) *Field {
}
if _, ok := field.TagSettings["EMBEDDED"]; ok || (fieldStruct.Anonymous && !isValuer) {
if reflect.Indirect(fieldValue).Kind() == reflect.Struct {
var err error
field.Creatable = false
field.Updatable = false
@ -342,6 +343,9 @@ func (schema *Schema) ParseField(fieldStruct reflect.StructField) *Field {
field.Schema.QueryClauses = append(field.Schema.QueryClauses, field.EmbeddedSchema.QueryClauses...)
field.Schema.UpdateClauses = append(field.Schema.UpdateClauses, field.EmbeddedSchema.UpdateClauses...)
field.Schema.DeleteClauses = append(field.Schema.DeleteClauses, field.EmbeddedSchema.DeleteClauses...)
} else {
schema.err = fmt.Errorf("invalid embedded struct for %v's field %v, should be struct, but got %v", field.Schema.Name, field.Name, field.FieldType)
}
}
return field