Second part of the defaultTableName field race fix (#2060)

* fix (https://github.com/jinzhu/gorm/issues/1407)

* changed map with mutex to sync.Map (https://github.com/jinzhu/gorm/issues/1407)

* removed newModelStructsMap func

* commit to rerun pipeline, comment changed

* fix race with defaultTableName field (again)
This commit is contained in:
Artemij Shepelev 2018-09-22 14:59:11 +03:00 committed by Jinzhu
parent 5be9bd3413
commit f6260a0085
1 changed files with 5 additions and 0 deletions

View File

@ -24,11 +24,16 @@ type ModelStruct struct {
PrimaryFields []*StructField
StructFields []*StructField
ModelType reflect.Type
defaultTableName string
l sync.Mutex
}
// TableName returns model's table name
func (s *ModelStruct) TableName(db *DB) string {
s.l.Lock()
defer s.l.Unlock()
if s.defaultTableName == "" && db != nil && s.ModelType != nil {
// Set default table name
if tabler, ok := reflect.New(s.ModelType).Interface().(tabler); ok {