mirror of
https://github.com/ent/ent.git
synced 2026-04-29 06:00:55 +03:00
entc/gen: filter duplicate ids when loading o2m/m2o edges
This commit is contained in:
committed by
Ariel Mashraki
parent
0f7739d83b
commit
6ab0d01ea4
@@ -317,16 +317,16 @@ func ({{ $receiver }} *{{ $builder }}) sqlQuery(ctx context.Context) *sql.Select
|
||||
nodeids := make(map[{{ $e.Type.ID.Type }}][]*{{ $.Name }})
|
||||
for i := range nodes {
|
||||
{{- $fk := $e.ForeignKey }}
|
||||
fk := nodes[i].{{ $fk.StructField }}
|
||||
{{- if $fk.Field.Nillable }}
|
||||
if fk != nil {
|
||||
ids = append(ids, *fk)
|
||||
nodeids[*fk] = append(nodeids[*fk], nodes[i])
|
||||
if nodes[i].{{ $fk.StructField }} == nil {
|
||||
continue
|
||||
}
|
||||
{{- else }}
|
||||
ids = append(ids, fk)
|
||||
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||
{{- end }}
|
||||
fk := {{ if $fk.Field.Nillable }}*{{ end }}nodes[i].{{ $fk.StructField }}
|
||||
if _, ok := nodeids[fk]; !ok {
|
||||
ids = append(ids, fk)
|
||||
}
|
||||
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||
}
|
||||
query.Where({{ $e.Type.Package }}.IDIn(ids...))
|
||||
neighbors, err := query.All(ctx)
|
||||
|
||||
Reference in New Issue
Block a user