fix: replace empty name result in panic
This commit is contained in:
		
							parent
							
								
									f19b84d104
								
							
						
					
					
						commit
						e31a21bfc0
					
				@ -120,7 +120,14 @@ 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