mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
entc/gen: make generated client to implement the ent.Mutator interface (#3161)
This commit is contained in:
@@ -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 }}
|
||||
}
|
||||
|
||||
@@ -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 }}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user