mirror of https://github.com/go-gorm/gorm.git
Returns error for invalid embedded field, close #3209
This commit is contained in:
parent
a140908839
commit
2cbdd29f26
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue