add id field to update (#159)

This commit is contained in:
Asim Aslam
2021-06-15 11:00:04 +01:00
committed by GitHub
parent 649b2e3f78
commit e1c2c92baf
4 changed files with 60 additions and 22 deletions

View File

@@ -133,9 +133,15 @@ func (e *Db) Update(ctx context.Context, req *db.UpdateRequest, rsp *db.UpdateRe
m := req.Record.AsMap()
// where ID is specified do a single update record update
id, ok := m[idKey].(string)
if !ok {
return fmt.Errorf("update failed: missing id")
id := req.Id
// if the id is blank then check the data
if len(req.Id) == 0 {
var ok bool
id, ok = m[idKey].(string)
if !ok {
return fmt.Errorf("update failed: missing id")
}
}
return db.Transaction(func(tx *gorm.DB) error {