From e421486ca9713323f25ce66f46a5ad78b5388bf0 Mon Sep 17 00:00:00 2001 From: Janos Dobronszki Date: Wed, 23 Jun 2021 13:55:09 +0100 Subject: [PATCH] Fix db update when id is not in record (#171) --- db/handler/db.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/db/handler/db.go b/db/handler/db.go index 7805453..2735feb 100644 --- a/db/handler/db.go +++ b/db/handler/db.go @@ -134,6 +134,9 @@ func (e *Db) Update(ctx context.Context, req *db.UpdateRequest, rsp *db.UpdateRe // where ID is specified do a single update record update id := req.Id + if v, ok := m[idKey].(string); ok && id == "" { + id = v + } // if the id is blank then check the data if len(req.Id) == 0 { @@ -164,7 +167,7 @@ func (e *Db) Update(ctx context.Context, req *db.UpdateRequest, rsp *db.UpdateRe bs, _ := json.Marshal(old) return tx.Table(tableName).Save(&Record{ - ID: m[idKey].(string), + ID: id, Data: bs, }).Error })