From a7e640a6a1e5957cd0247d9eb4e7fb995010e772 Mon Sep 17 00:00:00 2001 From: Hein Date: Wed, 7 Jan 2026 11:58:44 +0200 Subject: [PATCH] =?UTF-8?q?fix(recursive=5Fcrud):=20=F0=9F=90=9B=20use=20d?= =?UTF-8?q?ynamic=20primary=20key=20name=20in=20insert=20*=20Update=20proc?= =?UTF-8?q?essInsert=20to=20use=20the=20primary=20key=20name=20dynamically?= =?UTF-8?q?.=20*=20Ensure=20correct=20ID=20retrieval=20from=20data=20based?= =?UTF-8?q?=20on=20primary=20key.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/common/recursive_crud.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/common/recursive_crud.go b/pkg/common/recursive_crud.go index 13b6f89..6e047fb 100644 --- a/pkg/common/recursive_crud.go +++ b/pkg/common/recursive_crud.go @@ -207,9 +207,9 @@ func (p *NestedCUDProcessor) processInsert( for key, value := range data { query = query.Value(key, value) } - + pkName := reflection.GetPrimaryKeyName(tableName) // Add RETURNING clause to get the inserted ID - query = query.Returning("id") + query = query.Returning(pkName) result, err := query.Exec(ctx) if err != nil { @@ -220,8 +220,8 @@ func (p *NestedCUDProcessor) processInsert( var id interface{} if lastID, err := result.LastInsertId(); err == nil && lastID > 0 { id = lastID - } else if data["id"] != nil { - id = data["id"] + } else if data[pkName] != nil { + id = data[pkName] } logger.Debug("Insert successful, ID: %v, rows affected: %d", id, result.RowsAffected())