mirror of https://github.com/go-gorm/gorm.git
parent
0a51f6cdc5
commit
2ff44ee8d7
|
@ -146,7 +146,7 @@ func (commonDialect) LastInsertIDReturningSuffix(tableName, columnName string) s
|
||||||
|
|
||||||
func (DefaultForeignKeyNamer) BuildForeignKeyName(tableName, field, dest string) string {
|
func (DefaultForeignKeyNamer) BuildForeignKeyName(tableName, field, dest string) string {
|
||||||
keyName := fmt.Sprintf("%s_%s_%s_foreign", tableName, field, dest)
|
keyName := fmt.Sprintf("%s_%s_%s_foreign", tableName, field, dest)
|
||||||
keyName = regexp.MustCompile("(_*[^a-zA-Z]+_*|_+)").ReplaceAllString(keyName, "_")
|
keyName = regexp.MustCompile("[^a-zA-Z0-9]+").ReplaceAllString(keyName, "_")
|
||||||
return keyName
|
return keyName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -166,8 +166,8 @@ func (s mysql) BuildForeignKeyName(tableName, field, dest string) string {
|
||||||
h.Write([]byte(keyName))
|
h.Write([]byte(keyName))
|
||||||
bs := h.Sum(nil)
|
bs := h.Sum(nil)
|
||||||
|
|
||||||
// sha1 is 40 digits, keep first 24 characters of destination
|
// sha1 is 40 characters, keep first 24 characters of destination
|
||||||
destRunes := []rune(regexp.MustCompile("(_*[^a-zA-Z]+_*|_+)").ReplaceAllString(dest, "_"))
|
destRunes := []rune(regexp.MustCompile("[^a-zA-Z0-9]+").ReplaceAllString(dest, "_"))
|
||||||
if len(destRunes) > 24 {
|
if len(destRunes) > 24 {
|
||||||
destRunes = destRunes[:24]
|
destRunes = destRunes[:24]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue