8000 Generate table name with struct filed get Incorrect name?? · Issue #3183 · go-gorm/gorm · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Generate table name with struct filed get Incorrect name?? #3183
Closed
@thinkgos

Description

@thinkgos

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0