mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +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
@@ -381,11 +381,14 @@ func (pq *PetQuery) sqlAll(ctx context.Context) ([]*Pet, error) {
|
||||
ids := make([]int, 0, len(nodes))
|
||||
nodeids := make(map[int][]*Pet)
|
||||
for i := range nodes {
|
||||
fk := nodes[i].user_pets
|
||||
if fk != nil {
|
||||
ids = append(ids, *fk)
|
||||
nodeids[*fk] = append(nodeids[*fk], nodes[i])
|
||||
if nodes[i].user_pets == nil {
|
||||
continue
|
||||
}
|
||||
fk := *nodes[i].user_pets
|
||||
if _, ok := nodeids[fk]; !ok {
|
||||
ids = append(ids, fk)
|
||||
}
|
||||
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||
}
|
||||
query.Where(user.IDIn(ids...))
|
||||
neighbors, err := query.All(ctx)
|
||||
|
||||
Reference in New Issue
Block a user