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

fix: 字段名称转换误用SchemaName,修正为ColumnName #1232

Closed
wants to merge 1 commit into from

Conversation

Albelt
Copy link

@Albelt Albelt commented Oct 29, 2024

  • Do only one thing
  • Non breaking API changes
  • Tested

What did this pull request do?

遇到了这个问题 issues/969,通过gorm gen转换后发现原来SQL字段名称中的下划线消失了,导致了比如"X_Y"和"XY"都转换成了"XY",最终的Model里面有两个同名的字段。

查看源码后发现在转换字段时,貌似误用了SchemaName()函数,修改为ColumnName()就没问题了。

User Case Description

SQL DDL:

CREATE TABLE XXX (
	STOCKUNIT numeric(1,0) NOT NULL,
	STOCK_UNIT nvarchar(20) COLLATE Latin1_General_BIN NOT NULL,
	...
)

修改前生成的Model:

// PRICE mapped from table <PRICE>
type PRICE struct {
	STOCKUNIT  int32     `gorm:"column:STOCKUNIT;type:numeric;not null" json:"STOCKUNIT"`
	STOCKUNIT string    `gorm:"column:STOCK_UNIT;type:nvarchar;not null" json:"STOCK_UNIT"`
	...
}

修改后生成的Model:

// PRICE mapped from table <PRICE>
type PRICE struct {
	STOCKUNIT  int32     `gorm:"column:STOCKUNIT;type:numeric;not null" json:"STOCKUNIT"`
	STOCK_UNIT string    `gorm:"column:STOCK_UNIT;type:nvarchar;not null" json:"STOCK_UNIT"`
	...
}

@Albelt Albelt closed this Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant