Skip to content

Commit

Permalink
🩹 修复结构体主键字段类型为指针时无法获取自增主键返回值的问题
Browse files Browse the repository at this point in the history
使用 gorm.io/gen 时可能会导致主键字段被自动转换为指针。

另外,gen 默认会自动在表名和别名之间拼接 AS 关键字,而 oracle 数据库不支持此语法,需要自行去掉表名和别名之间的 AS 关键字。

Fix #11

Signed-off-by: liutianqi <[email protected]>
  • Loading branch information
iTanken committed Jan 18, 2024
1 parent 953a73d commit d105a1d
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions create.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ func getDefaultValues(db *gorm.DB, idx int) {
insertTo = insertTo.Index(idx)
default:
}
if insertTo.Kind() == reflect.Pointer {
insertTo = insertTo.Elem()
}

for _, val := range db.Statement.Vars {
switch v := val.(type) {
Expand Down

0 comments on commit d105a1d

Please sign in to comment.