entc/gen: filter duplicate ids when loading m2m edges

This commit is contained in:
Ariel Mashraki
2021-03-15 22:35:36 +02:00
committed by Ariel Mashraki
parent 6ab0d01ea4
commit e92dfee33f
31 changed files with 121 additions and 75 deletions

View File

@@ -464,7 +464,6 @@ func (bq *BlobQuery) sqlAll(ctx context.Context) ([]*Blob, error) {
Predicate: func(s *sql.Selector) {
s.Where(sql.InValues(blob.LinksPrimaryKey[0], fks...))
},
ScanValues: func() [2]interface{} {
return [2]interface{}{&uuid.UUID{}, &uuid.UUID{}}
},
@@ -483,7 +482,9 @@ func (bq *BlobQuery) sqlAll(ctx context.Context) ([]*Blob, error) {
if !ok {
return fmt.Errorf("unexpected node id in edges: %v", outValue)
}
edgeids = append(edgeids, inValue)
if _, ok := edges[inValue]; !ok {
edgeids = append(edgeids, inValue)
}
edges[inValue] = append(edges[inValue], node)
return nil
},

View File

@@ -367,7 +367,6 @@ func (gq *GroupQuery) sqlAll(ctx context.Context) ([]*Group, error) {
Predicate: func(s *sql.Selector) {
s.Where(sql.InValues(group.UsersPrimaryKey[0], fks...))
},
ScanValues: func() [2]interface{} {
return [2]interface{}{&sql.NullInt64{}, &sql.NullInt64{}}
},
@@ -386,7 +385,9 @@ func (gq *GroupQuery) sqlAll(ctx context.Context) ([]*Group, error) {
if !ok {
return fmt.Errorf("unexpected node id in edges: %v", outValue)
}
edgeids = append(edgeids, inValue)
if _, ok := edges[inValue]; !ok {
edgeids = append(edgeids, inValue)
}
edges[inValue] = append(edges[inValue], node)
return nil
},

View File

@@ -542,7 +542,6 @@ func (pq *PetQuery) sqlAll(ctx context.Context) ([]*Pet, error) {
Predicate: func(s *sql.Selector) {
s.Where(sql.InValues(pet.FriendsPrimaryKey[0], fks...))
},
ScanValues: func() [2]interface{} {
return [2]interface{}{&sql.NullString{}, &sql.NullString{}}
},
@@ -561,7 +560,9 @@ func (pq *PetQuery) sqlAll(ctx context.Context) ([]*Pet, error) {
if !ok {
return fmt.Errorf("unexpected node id in edges: %v", outValue)
}
edgeids = append(edgeids, inValue)
if _, ok := edges[inValue]; !ok {
edgeids = append(edgeids, inValue)
}
edges[inValue] = append(edges[inValue], node)
return nil
},

View File

@@ -484,7 +484,6 @@ func (uq *UserQuery) sqlAll(ctx context.Context) ([]*User, error) {
Predicate: func(s *sql.Selector) {
s.Where(sql.InValues(user.GroupsPrimaryKey[1], fks...))
},
ScanValues: func() [2]interface{} {
return [2]interface{}{&sql.NullInt64{}, &sql.NullInt64{}}
},
@@ -503,7 +502,9 @@ func (uq *UserQuery) sqlAll(ctx context.Context) ([]*User, error) {
if !ok {
return fmt.Errorf("unexpected node id in edges: %v", outValue)
}
edgeids = append(edgeids, inValue)
if _, ok := edges[inValue]; !ok {
edgeids = append(edgeids, inValue)
}
edges[inValue] = append(edges[inValue], node)
return nil
},