You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
936 B
Cheetah
26 lines
936 B
Cheetah
{{/* gotype: entgo.io/ent/entc/gen.Graph */}}
|
|
|
|
|
|
{{ define "set_not_nil" }}
|
|
|
|
{{/* Add the base header for the generated file */}}
|
|
{{ $pkg := base $.Config.Package }}
|
|
{{ template "header" $ }}
|
|
|
|
{{/* Loop over all updaters and implement the "SetNotNil" method for all optional fields */}}
|
|
{{ range $n := $.Nodes }}
|
|
{{ range $f := $n.MutableFields }}
|
|
{{ $set := print "Set" $f.StructField }}
|
|
|
|
{{ range $updater := list $n.UpdateName $n.UpdateOneName $n.CreateName}}
|
|
// set field if value's pointer is not nil.
|
|
func ({{ $n.Receiver }} *{{ $updater }}) SetNotNil{{ $f.StructField }}(value *{{ $f.Type }}) *{{ $updater }} {
|
|
if value != nil {
|
|
return {{ $n.Receiver }}.{{ $set }}(*value)
|
|
}
|
|
return {{ $n.Receiver }}
|
|
}
|
|
{{ end }}
|
|
{{ end }}
|
|
{{ end }}
|
|
{{ end }} |