File tree Expand file tree Collapse file tree 2 files changed +7
-2
lines changed Expand file tree Collapse file tree 2 files changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ import (
24
24
// +gplus:column=true
25
25
26
26
type User struct {
27
- ID int64
27
+ ID int64 `gorm:"primaryKey"`
28
28
Username string `gorm:"column:username"`
29
29
Password string
30
30
Address string
Original file line number Diff line number Diff line change @@ -235,7 +235,12 @@ func getPKColumn[T any]() string {
235
235
tagSetting := schema .ParseTagSetting (field .Tag .Get ("gorm" ), ";" )
236
236
isPrimaryKey := utils .CheckTruth (tagSetting ["PRIMARYKEY" ], tagSetting ["PRIMARY_KEY" ])
237
237
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
239
244
break
240
245
}
241
246
}
You can’t perform that action at this time.
0 commit comments