entc/gen: allow selecting partial fields on update-one

This commit is contained in:
Ariel Mashraki
2021-03-14 15:55:17 +02:00
committed by Ariel Mashraki
parent 0cd637ceb2
commit 5d70144f44
96 changed files with 1814 additions and 22 deletions

View File

@@ -30,6 +30,18 @@ func ({{ $receiver }} *{{ $builder }}) sqlSave(ctx context.Context) ({{ $ret }}
return {{ $zero }}, &ValidationError{Name: "ID", err: fmt.Errorf("missing {{ $.Name }}.ID for update")}
}
_spec.Node.ID.Value = id
if fields := {{ $receiver }}.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, {{ $.Package }}.{{ $.ID.Constant }})
for _, f := range fields {
if !{{ $.Package }}.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("{{ $pkg }}: invalid field %q for query", f)}
}
if f != {{ $.Package }}.{{ $.ID.Constant }} {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
{{- end }}
if ps := {{ $mutation }}.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {