Skip to content

Commit 11546ce

Browse files
committed
fix: fix get primaryKey name error
1 parent af0c087 commit 11546ce

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

example/base/user.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
// +gplus:column=true
2525

2626
type User struct {
27-
ID int64
27+
ID int64 `gorm:"primaryKey"`
2828
Username string `gorm:"column:username"`
2929
Password string
3030
Address string

gplus/base_dao.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,12 @@ func getPKColumn[T any]() string {
235235
tagSetting := schema.ParseTagSetting(field.Tag.Get("gorm"), ";")
236236
isPrimaryKey := utils.CheckTruth(tagSetting["PRIMARYKEY"], tagSetting["PRIMARY_KEY"])
237237
if isPrimaryKey {
238-
columnName = tagSetting["COLUMN"]
238+
name, ok := tagSetting["COLUMN"]
239+
if !ok {
240+
namingStrategy := schema.NamingStrategy{}
241+
name = namingStrategy.ColumnName("", field.Name)
242+
}
243+
columnName = name
239244
break
240245
}
241246
}

0 commit comments

Comments
 (0)