Closed
Description
GORM Playground Link
Description
in schem.go code 91-95
modelValue := reflect.New(modelType)
tableName := namer.TableName(modelType.Name())
if tabler, ok := modelValue.Interface().(Tabler); ok {
tableName = tabler.TableName()
}
why use reflect.New(modelType)??
if I define a struct like:
type Device struct {
ID uint `gorm:"primary_key"`
Name string `gorm:"size:32"`
TbNameSuffix int `gorm:"-"`
}
func (sf *Device) TableName() string {
return "devices_"+strconv.Itoa(sf.TbNameSuffix)
}
i want to generate table name dynamically: device_0,devices_1,... with give struct field TbNameSuffix.
I want to dynamically generated table name, alway get devices_0
.