GORM Playground Link

https://github.com/go-gorm/playground/pull/432

Description

我想使用 NameReplacer: strings.NewReplacer("Model", "") 替换掉我结构体的名称后缀作为表名

&gorm.Config{
        // Logger: newlogger,
    Logger: logger.Default.LogMode(logger.Info),
    NamingStrategy: schema.NamingStrategy{
        TablePrefix:   tablePrefix,
        SingularTable: true,
        // 
        NameReplacer: strings.NewReplacer("Model", ""),
    },
    DisableForeignKeyConstraintWhenMigrating: true,
}

我的结构体继承了gorm.Model

type UserModel struct {
    gorm.Model
        Name string
}

但是我在运行的时候发现 *gorm.Model,也会被执行表名称替换的代码,Schema.ParseField中的getOrParse会把结构体替换为表名,表名转换会返回 "",在执行NamingStrategy.toDBName 这个方法的时候 curCase = value[0] <= 'Z' && value[0] >= 'A' 报错下标溢出。

一个暂时 且有效的解决方案 需要自己给 gorm.Model 取一个别名。然后使用这个别名类型,像这样:

type MyModel gorm.Model

type UserModel struct {
    MyModel
        Name string
}

Gorm NameReplacer: strings.NewReplacer( Gorm NameReplacer: strings.NewReplacer(