Skip to content

Commit

Permalink
fix: fix get primaryKey name error
Browse files Browse the repository at this point in the history
  • Loading branch information
afumu committed Jan 16, 2023
1 parent af0c087 commit 11546ce
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion example/base/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
// +gplus:column=true

type User struct {
ID int64
ID int64 `gorm:"primaryKey"`
Username string `gorm:"column:username"`
Password string
Address string
Expand Down
7 changes: 6 additions & 1 deletion gplus/base_dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,12 @@ func getPKColumn[T any]() string {
tagSetting := schema.ParseTagSetting(field.Tag.Get("gorm"), ";")
isPrimaryKey := utils.CheckTruth(tagSetting["PRIMARYKEY"], tagSetting["PRIMARY_KEY"])
if isPrimaryKey {
columnName = tagSetting["COLUMN"]
name, ok := tagSetting["COLUMN"]
if !ok {
namingStrategy := schema.NamingStrategy{}
name = namingStrategy.ColumnName("", field.Name)
}
columnName = name
break
}
}
Expand Down

0 comments on commit 11546ce

Please sign in to comment.