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:
parent
5be9bd3413
commit
f6260a0085
@ -24,11 +24,16 @@ type ModelStruct struct {
|
|||||||
PrimaryFields []*StructField
|
PrimaryFields []*StructField
|
||||||
StructFields []*StructField
|
StructFields []*StructField
|
||||||
ModelType reflect.Type
|
ModelType reflect.Type
|
||||||
|
|
||||||
defaultTableName string
|
defaultTableName string
|
||||||
|
l sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// TableName returns model's table name
|
// TableName returns model's table name
|
||||||
func (s *ModelStruct) TableName(db *DB) string {
|
func (s *ModelStruct) TableName(db *DB) string {
|
||||||
|
s.l.Lock()
|
||||||
|
defer s.l.Unlock()
|
||||||
|
|
||||||
if s.defaultTableName == "" && db != nil && s.ModelType != nil {
|
if s.defaultTableName == "" && db != nil && s.ModelType != nil {
|
||||||
// Set default table name
|
// Set default table name
|
||||||
if tabler, ok := reflect.New(s.ModelType).Interface().(tabler); ok {
|
if tabler, ok := reflect.New(s.ModelType).Interface().(tabler); ok {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user