From 12381f43fa0338129ff1224a0f287e3bfdcd8027 Mon Sep 17 00:00:00 2001 From: Stephen Afam-Osemene Date: Sat, 18 Nov 2023 01:26:42 +0000 Subject: [PATCH] Generate setter if a table has relationships --- gen/templates/models/01_types.go.tpl | 3 +-- gen/templates/models/11_rel_ops.go.tpl | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/gen/templates/models/01_types.go.tpl b/gen/templates/models/01_types.go.tpl index 4043d993..6b827deb 100644 --- a/gen/templates/models/01_types.go.tpl +++ b/gen/templates/models/01_types.go.tpl @@ -67,7 +67,7 @@ type {{$tAlias.DownSingular}}R struct { } {{- end}} -{{if .Table.PKey -}} +{{if or .Table.PKey .Table.Relationships -}} // {{$tAlias.UpSingular}}Setter is used for insert/upsert/update operations // All values are optional, and do not have to be set // Generated columns are not included @@ -223,4 +223,3 @@ func {{$tAlias.UpSingular}}Where[Q {{$.Dialect}}.Filterable]() {{$tAlias.DownSin {{end -}} } } - diff --git a/gen/templates/models/11_rel_ops.go.tpl b/gen/templates/models/11_rel_ops.go.tpl index 12a3ad54..8c4b3538 100644 --- a/gen/templates/models/11_rel_ops.go.tpl +++ b/gen/templates/models/11_rel_ops.go.tpl @@ -1,3 +1,4 @@ +{{if .Table.PKey -}} {{$table := .Table}} {{$tAlias := .Aliases.Table $table.Key -}} @@ -320,3 +321,4 @@ {{end -}}{{end -}} +{{- end}}