Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate table name with struct filed get Incorrect name?? #3183

Closed
thinkgos opened this issue Jul 22, 2020 · 3 comments
Closed

Generate table name with struct filed get Incorrect name?? #3183

thinkgos opened this issue Jul 22, 2020 · 3 comments
Assignees
Labels

Comments

@thinkgos
Copy link

GORM Playground Link

go-gorm/playground#1

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.

@github-actions github-actions bot added the type:missing reproduction steps missing reproduction steps label Jul 22, 2020
@github-actions
Copy link

This issue has been automatically marked as stale as it missing playground pull request link, checkout https://github.com/go-gorm/playground for details, it will be closed in 2 days if no further activity occurs.

@jinzhu
Copy link
Member

jinzhu commented Jul 22, 2020

@jinzhu jinzhu closed this as completed Jul 22, 2020
@thinkgos
Copy link
Author

thinks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants