dialect/sql/sqlgraph: apply predicate on update-node

This commit is contained in:
Ariel Mashraki
2021-01-22 22:45:04 +02:00
committed by Ariel Mashraki
parent 5e4d7dcbfc
commit f315801779
70 changed files with 485 additions and 13 deletions

View File

@@ -30,15 +30,14 @@ 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
{{- else }}
if ps := {{ $mutation }}.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
{{- end }}
if ps := {{ $mutation }}.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
{{- end }}
}
{{- range $f := $.Fields }}
{{- if or (not $f.Immutable) $f.UpdateDefault }}
if value, ok := {{ $mutation }}.{{ $f.MutationGet }}(); ok {