entc/gen: change eager-loading empty values (#791)

When loading relations (using edger-loading) and there are no changes,
the response should be an empty slice (and not nil). Similar to the
way we handle simple queries (e.g. All()).

Closed #790
This commit is contained in:
Ariel Mashraki
2020-09-22 20:22:30 +03:00
committed by GitHub
parent ae30bc192a
commit 49101d7d05
33 changed files with 66 additions and 2 deletions

View File

@@ -369,6 +369,7 @@ func (gq *GroupQuery) sqlAll(ctx context.Context) ([]*Group, error) {
for _, node := range nodes {
ids[node.ID] = node
fks = append(fks, node.ID)
node.Edges.Users = []*User{}
}
var (
edgeids []int

View File

@@ -405,6 +405,7 @@ func (uq *UserQuery) sqlAll(ctx context.Context) ([]*User, error) {
for i := range nodes {
fks = append(fks, nodes[i].ID)
nodeids[nodes[i].ID] = nodes[i]
nodes[i].Edges.Cars = []*Car{}
}
query.withFKs = true
query.Where(predicate.Car(func(s *sql.Selector) {
@@ -433,6 +434,7 @@ func (uq *UserQuery) sqlAll(ctx context.Context) ([]*User, error) {
for _, node := range nodes {
ids[node.ID] = node
fks = append(fks, node.ID)
node.Edges.Groups = []*Group{}
}
var (
edgeids []int