fix(handler): re-fetch records to capture DB-generated changes

This commit is contained in:
Hein
2026-06-12 13:37:07 +02:00
parent c120b49529
commit 1419542650
2 changed files with 44 additions and 0 deletions
+6
View File
@@ -671,6 +671,12 @@ func (h *Handler) create(hookCtx *HookContext) (interface{}, error) {
return nil, fmt.Errorf("failed to create record: %w", err)
}
// Re-fetch the created record to capture DB-generated defaults/triggers.
if pkVal := reflection.GetPrimaryKeyValue(hookCtx.ModelPtr); pkVal != nil {
hookCtx.ID = fmt.Sprintf("%v", pkVal)
return h.readByID(hookCtx)
}
return hookCtx.ModelPtr, nil
}