GORM Playground Link
i have a struct
type Logs struct {
ID int64 gorm:"id"
Content string gorm:"content"
LogTime int64 gorm:"logtime"
}
func (l *Logs)TableName() string{ return "logs_"+Unix(l.LogTime, 0).Format("200601") }
whatever the Logs.LogTime is , gorm create record will always get a "logs_197001" table name.
I found that happen because of the reason bellow
in gorm.io/gorm/schema/schema.go:150 it use: modelValue := reflect.New(modelType) not the value from its params: so it should be: modelValue := value (which from the function params)
Comment From: VitAndrGuid
https://gorm.io/docs/conventions.html#Pluralized-Table-Name:~:text=NOTE%20TableName%20doesn%E2%80%99t%20allow%20dynamic%20name%2C%20its%20result%20will%20be%20cached%20for%20future%2C%20to%20use%20dynamic%20name%2C%20you%20can%20use%20Scopes%2C%20for%20example%3A
Comment From: jackylong1
thanks