fix: replace empty table name result in panic (#5048)
* fix: replace empty name result in panic * fix: replace empty table name result in panic
This commit is contained in:
		
							parent
							
								
									416c4d0653
								
							
						
					
					
						commit
						d22215129e
					
				| @ -120,7 +120,13 @@ func (ns NamingStrategy) toDBName(name string) string { | ||||
| 	} | ||||
| 
 | ||||
| 	if ns.NameReplacer != nil { | ||||
| 		name = ns.NameReplacer.Replace(name) | ||||
| 		tmpName := ns.NameReplacer.Replace(name) | ||||
| 
 | ||||
| 		if tmpName == "" { | ||||
| 			return name | ||||
| 		} | ||||
| 
 | ||||
| 		name = tmpName | ||||
| 	} | ||||
| 
 | ||||
| 	if ns.NoLowerCase { | ||||
|  | ||||
| @ -197,3 +197,14 @@ func TestFormatNameWithStringLongerThan64Characters(t *testing.T) { | ||||
| 		t.Errorf("invalid formatted name generated, got %v", formattedName) | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func TestReplaceEmptyTableName(t *testing.T) { | ||||
| 	ns := NamingStrategy{ | ||||
| 		SingularTable: true, | ||||
| 		NameReplacer:  strings.NewReplacer("Model", ""), | ||||
| 	} | ||||
| 	tableName := ns.TableName("Model") | ||||
| 	if tableName != "Model" { | ||||
| 		t.Errorf("invalid table name generated, got %v", tableName) | ||||
| 	} | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 li-jin-gou
						li-jin-gou