mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
entc/gen: allow selecting partial fields on update-one
This commit is contained in:
committed by
Ariel Mashraki
parent
0cd637ceb2
commit
5d70144f44
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user