Skip to content

Commit 9ca84b3

Browse files
authored
fix concurrent map writes (#7298)
1 parent 86b1d22 commit 9ca84b3

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

schema/relationship.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"reflect"
77
"strings"
8+
"sync"
89

910
"github.com/jinzhu/inflection"
1011
"golang.org/x/text/cases"
@@ -32,6 +33,8 @@ type Relationships struct {
3233
Relations map[string]*Relationship
3334

3435
EmbeddedRelations map[string]*Relationships
36+
37+
Mux sync.RWMutex
3538
}
3639

3740
type Relationship struct {
@@ -98,9 +101,10 @@ func (schema *Schema) parseRelation(field *Field) *Relationship {
98101
}
99102

100103
if relation.Type == has {
101-
// don't add relations to embedded schema, which might be shared
102104
if relation.FieldSchema != relation.Schema && relation.Polymorphic == nil && field.OwnerSchema == nil {
105+
relation.FieldSchema.Relationships.Mux.Lock()
103106
relation.FieldSchema.Relationships.Relations["_"+relation.Schema.Name+"_"+relation.Name] = relation
107+
relation.FieldSchema.Relationships.Mux.Unlock()
104108
}
105109

106110
switch field.IndirectFieldType.Kind() {

0 commit comments

Comments
 (0)