Merge bc97f72517d47fae875e822fbc876b3e202404c2 into 6cc2c01268c24fdf7b30cfe4b1a8fb5a10922c65
This commit is contained in:
		
						commit
						30034d60a0
					
				| @ -138,14 +138,14 @@ func preloadEntryPoint(db *gorm.DB, joins []string, relationships *schema.Relati | |||||||
| 						} | 						} | ||||||
| 
 | 
 | ||||||
| 						tx := preloadDB(db, reflectValue, reflectValue.Interface()) | 						tx := preloadDB(db, reflectValue, reflectValue.Interface()) | ||||||
| 						if err := preloadEntryPoint(tx, nestedJoins, &tx.Statement.Schema.Relationships, preloadMap[name], associationsConds); err != nil { | 						if err := preloadEntryPoint(tx, nestedJoins, tx.Statement.Schema.Relationships, preloadMap[name], associationsConds); err != nil { | ||||||
| 							return err | 							return err | ||||||
| 						} | 						} | ||||||
| 					} | 					} | ||||||
| 				case reflect.Struct, reflect.Pointer: | 				case reflect.Struct, reflect.Pointer: | ||||||
| 					reflectValue := rel.Field.ReflectValueOf(db.Statement.Context, rv) | 					reflectValue := rel.Field.ReflectValueOf(db.Statement.Context, rv) | ||||||
| 					tx := preloadDB(db, reflectValue, reflectValue.Interface()) | 					tx := preloadDB(db, reflectValue, reflectValue.Interface()) | ||||||
| 					if err := preloadEntryPoint(tx, nestedJoins, &tx.Statement.Schema.Relationships, preloadMap[name], associationsConds); err != nil { | 					if err := preloadEntryPoint(tx, nestedJoins, tx.Statement.Schema.Relationships, preloadMap[name], associationsConds); err != nil { | ||||||
| 						return err | 						return err | ||||||
| 					} | 					} | ||||||
| 				default: | 				default: | ||||||
|  | |||||||
| @ -291,7 +291,7 @@ func Preload(db *gorm.DB) { | |||||||
| 			return | 			return | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		db.AddError(preloadEntryPoint(tx, joins, &tx.Statement.Schema.Relationships, db.Statement.Preloads, db.Statement.Preloads[clause.Associations])) | 		db.AddError(preloadEntryPoint(tx, joins, tx.Statement.Schema.Relationships, db.Statement.Preloads, db.Statement.Preloads[clause.Associations])) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -160,7 +160,7 @@ func (schema *Schema) setRelation(relation *Relationship) { | |||||||
| 	if len(relation.Field.EmbeddedBindNames) <= 1 { | 	if len(relation.Field.EmbeddedBindNames) <= 1 { | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 	relationships := &schema.Relationships | 	relationships := schema.Relationships | ||||||
| 	for i, name := range relation.Field.EmbeddedBindNames { | 	for i, name := range relation.Field.EmbeddedBindNames { | ||||||
| 		if i < len(relation.Field.EmbeddedBindNames)-1 { | 		if i < len(relation.Field.EmbeddedBindNames)-1 { | ||||||
| 			if relationships.EmbeddedRelations == nil { | 			if relationships.EmbeddedRelations == nil { | ||||||
|  | |||||||
| @ -44,7 +44,7 @@ type Schema struct { | |||||||
| 	FieldsByBindName          map[string]*Field // embedded fields is 'Embed.Field'
 | 	FieldsByBindName          map[string]*Field // embedded fields is 'Embed.Field'
 | ||||||
| 	FieldsByDBName            map[string]*Field | 	FieldsByDBName            map[string]*Field | ||||||
| 	FieldsWithDefaultDBValue  []*Field // fields with default value assigned by database
 | 	FieldsWithDefaultDBValue  []*Field // fields with default value assigned by database
 | ||||||
| 	Relationships             Relationships | 	Relationships             *Relationships | ||||||
| 	CreateClauses             []clause.Interface | 	CreateClauses             []clause.Interface | ||||||
| 	QueryClauses              []clause.Interface | 	QueryClauses              []clause.Interface | ||||||
| 	UpdateClauses             []clause.Interface | 	UpdateClauses             []clause.Interface | ||||||
| @ -58,6 +58,7 @@ type Schema struct { | |||||||
| 	initialized               chan struct{} | 	initialized               chan struct{} | ||||||
| 	namer                     Namer | 	namer                     Namer | ||||||
| 	cacheStore                *sync.Map | 	cacheStore                *sync.Map | ||||||
|  | 	mux                       sync.RWMutex | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (schema Schema) String() string { | func (schema Schema) String() string { | ||||||
| @ -76,6 +77,8 @@ func (schema Schema) MakeSlice() reflect.Value { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (schema Schema) LookUpField(name string) *Field { | func (schema Schema) LookUpField(name string) *Field { | ||||||
|  | 	schema.mux.RLock() | ||||||
|  | 	defer schema.mux.RUnlock() | ||||||
| 	if field, ok := schema.FieldsByDBName[name]; ok { | 	if field, ok := schema.FieldsByDBName[name]; ok { | ||||||
| 		return field | 		return field | ||||||
| 	} | 	} | ||||||
| @ -99,9 +102,12 @@ func (schema Schema) LookUpFieldByBindName(bindNames []string, name string) *Fie | |||||||
| 	} | 	} | ||||||
| 	for i := len(bindNames) - 1; i >= 0; i-- { | 	for i := len(bindNames) - 1; i >= 0; i-- { | ||||||
| 		find := strings.Join(bindNames[:i], ".") + "." + name | 		find := strings.Join(bindNames[:i], ".") + "." + name | ||||||
|  | 		schema.mux.RLock() | ||||||
| 		if field, ok := schema.FieldsByBindName[find]; ok { | 		if field, ok := schema.FieldsByBindName[find]; ok { | ||||||
|  | 			schema.mux.RUnlock() | ||||||
| 			return field | 			return field | ||||||
| 		} | 		} | ||||||
|  | 		schema.mux.RUnlock() | ||||||
| 	} | 	} | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
| @ -185,7 +191,7 @@ func ParseWithSpecialTableName(dest interface{}, cacheStore *sync.Map, namer Nam | |||||||
| 		FieldsByName:     map[string]*Field{}, | 		FieldsByName:     map[string]*Field{}, | ||||||
| 		FieldsByBindName: map[string]*Field{}, | 		FieldsByBindName: map[string]*Field{}, | ||||||
| 		FieldsByDBName:   map[string]*Field{}, | 		FieldsByDBName:   map[string]*Field{}, | ||||||
| 		Relationships:    Relationships{Relations: map[string]*Relationship{}}, | 		Relationships:    &Relationships{Relations: map[string]*Relationship{}}, | ||||||
| 		cacheStore:       cacheStore, | 		cacheStore:       cacheStore, | ||||||
| 		namer:            namer, | 		namer:            namer, | ||||||
| 		initialized:      make(chan struct{}), | 		initialized:      make(chan struct{}), | ||||||
|  | |||||||
| @ -221,7 +221,7 @@ func checkEmbeddedRelations(t *testing.T, actual map[string]*schema.Relationship | |||||||
| 					t.Errorf("failed to find relation by name %s", n) | 					t.Errorf("failed to find relation by name %s", n) | ||||||
| 				} else { | 				} else { | ||||||
| 					checkSchemaRelation(t, &schema.Schema{ | 					checkSchemaRelation(t, &schema.Schema{ | ||||||
| 						Relationships: schema.Relationships{ | 						Relationships: &schema.Relationships{ | ||||||
| 							Relations: map[string]*schema.Relationship{n: rel}, | 							Relations: map[string]*schema.Relationship{n: rel}, | ||||||
| 						}, | 						}, | ||||||
| 					}, r) | 					}, r) | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 yuhj86
						yuhj86