entc/gen: make generated client to implement the ent.Mutator interface (#3161)

This commit is contained in:
Ariel Mashraki
2022-12-09 21:18:25 +02:00
committed by GitHub
parent 3f4916ff8b
commit d0c5afa705
85 changed files with 3522 additions and 22 deletions

View File

@@ -411,6 +411,11 @@ func (m *{{ $mutation }}) Op() Op {
return m.op
}
// SetOp allows setting the mutation operation.
func (m *{{ $mutation }}) SetOp(op Op) {
m.op = op
}
// Type returns the node type of this mutation ({{ $n.Name }}).
func (m *{{ $mutation }}) Type() string {
return m.typ
@@ -479,7 +484,7 @@ func (m *{{ $mutation }}) SetField(name string, value ent.Value) error {
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.Set{{ $f.StructField }}(v)
m.{{ $f.MutationSet }}(v)
return nil
{{- end }}
}

View File

@@ -26,9 +26,9 @@ in the LICENSE file in the root directory of this source tree.
func ({{ $receiver }} *{{ $builder }}) {{ $func }}({{ $p }} {{ $f.Type }}) *{{ $builder }} {
{{- /* setting numeric type override previous calls to Add. */}}
{{- if and $updater $f.SupportsMutationAdd }}
{{ $receiver }}.mutation.{{ print "Reset" $f.StructField }}()
{{ $receiver }}.mutation.{{ $f.MutationReset }}()
{{- end }}
{{ $receiver }}.mutation.{{ $func }}({{ $p }})
{{ $receiver }}.mutation.{{ $f.MutationSet }}({{ $p }})
return {{ $receiver }}
}