From 857db144488f039eeed4fd801a49cf365a653f8e Mon Sep 17 00:00:00 2001 From: Pavel Merzlyakov Date: Fri, 3 Nov 2023 20:51:46 +0300 Subject: [PATCH] fix saving diff for structs with pk fields only --- tpl/macros_struct.twig | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tpl/macros_struct.twig b/tpl/macros_struct.twig index c8f1847..e6344b4 100644 --- a/tpl/macros_struct.twig +++ b/tpl/macros_struct.twig @@ -149,8 +149,8 @@ func Save{{ ctx.s.name }}Diff(ctx context.Context, dbe metadb.Execer, rec {{ ctx values = append(values, rec.{{ f|fname }}) {% endfor %} + {% if ctx.raw_nonpk_fields|length > 0 %} initUpdateLen := updateBuilder.Len() - {% for f in ctx.raw_nonpk_fields %} if rec.{{ f|fname }}Changed() { queryBuilder.WriteString(",`{{ f.name }}`") @@ -164,6 +164,7 @@ func Save{{ ctx.s.name }}Diff(ctx context.Context, dbe metadb.Execer, rec {{ ctx values = append(values, rec.{{ f|fname }}) } {% endfor %} + {% endif %} {% if has_token(ctx.s, 'table_json_kv') %} var jsonBuilder strings.Builder