Skip to content

Commit

Permalink
fix concurrent map writes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ponywka committed Dec 9, 2024
1 parent 6bfccf8 commit bdc17d9
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion schema/relationship.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"reflect"
"strings"
"sync"

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

EmbeddedRelations map[string]*Relationships

Mux sync.RWMutex
}

type Relationship struct {
Expand Down Expand Up @@ -98,9 +101,10 @@ func (schema *Schema) parseRelation(field *Field) *Relationship {
}

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

switch field.IndirectFieldType.Kind() {
Expand Down

0 comments on commit bdc17d9

Please sign in to comment.