mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
entc/gen: skip checking required fields with db-based default values (#3204)
This commit is contained in:
@@ -104,9 +104,21 @@ func ({{ $receiver }} *{{ $builder }}) check() error {
|
||||
{{- range $f := $fields }}
|
||||
{{- $skip := false }}{{ if $.HasOneFieldID }}{{ if eq $f.Name $.ID.Name }}{{ $skip = true }}{{ end }}{{ end }}
|
||||
{{- if and (not $f.Optional) (not $skip) }}
|
||||
if _, ok := {{ $mutation }}.{{ $f.MutationGet }}(); !ok {
|
||||
return &ValidationError{Name: "{{ $f.Name }}", err: errors.New(`{{ $pkg }}: missing required field "{{ $.Name }}.{{ $f.Name }}"`)}
|
||||
}
|
||||
{{- $dialects := $f.RequiredFor }}
|
||||
{{- $n := len $dialects }}
|
||||
{{- if $n }}
|
||||
{{- $partially := ne $n (len $.Config.Storage.Dialects) }}
|
||||
{{- if $partially }}
|
||||
switch {{ $receiver }}.driver.Dialect() {
|
||||
case {{ join $dialects ", " }}:
|
||||
{{- end }}
|
||||
if _, ok := {{ $mutation }}.{{ $f.MutationGet }}(); !ok {
|
||||
return &ValidationError{Name: "{{ $f.Name }}", err: errors.New(`{{ $pkg }}: missing required field "{{ $.Name }}.{{ $f.Name }}"`)}
|
||||
}
|
||||
{{- if $partially }}
|
||||
}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- with or $f.Validators $f.IsEnum }}
|
||||
if v, ok := {{ $mutation }}.{{ $f.MutationGet }}(); ok {
|
||||
|
||||
Reference in New Issue
Block a user