Fix concurrent map writes, close #3126

This commit is contained in:
Jinzhu 2020-07-10 07:14:37 +08:00
parent c091cd6aa4
commit bc3728a18f
1 changed files with 7 additions and 7 deletions

View File

@ -207,13 +207,13 @@ func Parse(dest interface{}, cacheStore *sync.Map, namer Namer) (*Schema, error)
}
}
cacheStore.Store(modelType, schema)
// parse relations for unidentified fields
for _, field := range schema.Fields {
if field.DataType == "" && field.Creatable {
if schema.parseRelation(field); schema.err != nil {
return schema, schema.err
if _, loaded := cacheStore.LoadOrStore(modelType, schema); !loaded {
// parse relations for unidentified fields
for _, field := range schema.Fields {
if field.DataType == "" && field.Creatable {
if schema.parseRelation(field); schema.err != nil {
return schema, schema.err
}
}
}
}