entc/gen: filter duplicate ids when loading o2m/m2o edges

This commit is contained in:
Ariel Mashraki
2021-03-15 22:07:15 +02:00
committed by Ariel Mashraki
parent 0f7739d83b
commit 6ab0d01ea4
39 changed files with 286 additions and 163 deletions

View File

@@ -381,11 +381,14 @@ func (cq *CardQuery) sqlAll(ctx context.Context) ([]*Card, error) {
ids := make([]int, 0, len(nodes))
nodeids := make(map[int][]*Card)
for i := range nodes {
fk := nodes[i].user_card
if fk != nil {
ids = append(ids, *fk)
nodeids[*fk] = append(nodeids[*fk], nodes[i])
if nodes[i].user_card == nil {
continue
}
fk := *nodes[i].user_card
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)