mirror of
https://github.com/ent/ent.git
synced 2026-04-28 05:30:56 +03:00
entc/gen: fix conflict between set_id edge field and mutation fields (#4062)
This commit is contained in:
@@ -127,11 +127,7 @@ func ({{ $receiver }} *{{ $builder }}) check() error {
|
||||
{{- end }}
|
||||
{{- range $e := $.EdgesWithID }}
|
||||
{{- if not $e.Optional }}
|
||||
{{- if $e.Unique }}
|
||||
if _, ok := {{ $mutation }}.{{ $e.StructField }}ID(); !ok {
|
||||
{{- else }}
|
||||
if len({{ $mutation }}.{{ $e.StructField }}IDs()) == 0 {
|
||||
{{- end }}
|
||||
if len({{ $mutation }}.{{ $e.StructField }}IDs()) == 0 {
|
||||
return &ValidationError{Name: "{{ $e.Name }}", err: errors.New(`{{ $pkg }}: missing required edge "{{ $.Name }}.{{ $e.Name }}"`)}
|
||||
}
|
||||
{{- end }}
|
||||
|
||||
@@ -269,7 +269,7 @@ func ({{ $receiver }} *{{ $onebuilder }}) ExecX(ctx context.Context) {
|
||||
{{- end }}
|
||||
{{- range $e := $.Edges }}
|
||||
{{- if and $e.Unique (not $e.Optional) }}
|
||||
if _, ok := {{ $mutation }}.{{ $e.StructField }}ID(); {{ $mutation }}.{{ $e.StructField }}Cleared() && !ok {
|
||||
if {{ $mutation }}.{{ $e.StructField }}Cleared() && len({{ $mutation }}.{{ $e.StructField }}IDs()) > 0 {
|
||||
return errors.New(`{{ $pkg }}: clearing a required unique edge "{{ $.Name }}.{{ $e.Name }}"`)
|
||||
}
|
||||
{{- end }}
|
||||
|
||||
Reference in New Issue
Block a user