mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
entc/gen/eagerloading: ignore loading edges on empty result (#298)
* fix eagerloading while parent nodes is zero. * Update entc/gen/template/dialect/sql/query.tmpl Co-Authored-By: Ariel Mashraki <7413593+a8m@users.noreply.github.com> * Update entc/gen/template/dialect/sql/query.tmpl Co-Authored-By: Ariel Mashraki <7413593+a8m@users.noreply.github.com> * generate new assets Co-authored-by: Ariel Mashraki <7413593+a8m@users.noreply.github.com>
This commit is contained in:
committed by
Ariel Mashraki
parent
89fade53f6
commit
5cb40ff883
@@ -262,6 +262,10 @@ func (uq *UserQuery) sqlAll(ctx context.Context) ([]*User, error) {
|
||||
if err := sqlgraph.QueryNodes(ctx, uq.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -287,6 +287,10 @@ func (bq *BlobQuery) sqlAll(ctx context.Context) ([]*Blob, error) {
|
||||
if err := sqlgraph.QueryNodes(ctx, bq.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -290,6 +290,10 @@ func (gq *GroupQuery) sqlAll(ctx context.Context) ([]*Group, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
if query := gq.withUsers; query != nil {
|
||||
fks := make([]driver.Value, 0, len(nodes))
|
||||
ids := make(map[int]*Group, len(nodes))
|
||||
|
||||
@@ -349,6 +349,10 @@ func (uq *UserQuery) sqlAll(ctx context.Context) ([]*User, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
if query := uq.withGroups; query != nil {
|
||||
fks := make([]driver.Value, 0, len(nodes))
|
||||
ids := make(map[int]*User, len(nodes))
|
||||
|
||||
@@ -351,6 +351,10 @@ func (cq *CardQuery) sqlAll(ctx context.Context) ([]*Card, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
if query := cq.withOwner; query != nil {
|
||||
ids := make([]string, 0, len(nodes))
|
||||
nodeids := make(map[string][]*Card)
|
||||
|
||||
@@ -286,6 +286,10 @@ func (cq *CommentQuery) sqlAll(ctx context.Context) ([]*Comment, error) {
|
||||
if err := sqlgraph.QueryNodes(ctx, cq.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -286,6 +286,10 @@ func (ftq *FieldTypeQuery) sqlAll(ctx context.Context) ([]*FieldType, error) {
|
||||
if err := sqlgraph.QueryNodes(ctx, ftq.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -349,6 +349,10 @@ func (fq *FileQuery) sqlAll(ctx context.Context) ([]*File, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
if query := fq.withOwner; query != nil {
|
||||
ids := make([]string, 0, len(nodes))
|
||||
nodeids := make(map[string][]*File)
|
||||
|
||||
@@ -315,6 +315,10 @@ func (ftq *FileTypeQuery) sqlAll(ctx context.Context) ([]*FileType, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
if query := ftq.withFiles; query != nil {
|
||||
fks := make([]driver.Value, 0, len(nodes))
|
||||
nodeids := make(map[string]*FileType)
|
||||
|
||||
@@ -400,6 +400,10 @@ func (gq *GroupQuery) sqlAll(ctx context.Context) ([]*Group, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
if query := gq.withFiles; query != nil {
|
||||
fks := make([]driver.Value, 0, len(nodes))
|
||||
nodeids := make(map[string]*Group)
|
||||
|
||||
@@ -315,6 +315,10 @@ func (giq *GroupInfoQuery) sqlAll(ctx context.Context) ([]*GroupInfo, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
if query := giq.withGroups; query != nil {
|
||||
fks := make([]driver.Value, 0, len(nodes))
|
||||
nodeids := make(map[string]*GroupInfo)
|
||||
|
||||
@@ -262,6 +262,10 @@ func (iq *ItemQuery) sqlAll(ctx context.Context) ([]*Item, error) {
|
||||
if err := sqlgraph.QueryNodes(ctx, iq.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -349,6 +349,10 @@ func (nq *NodeQuery) sqlAll(ctx context.Context) ([]*Node, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
if query := nq.withPrev; query != nil {
|
||||
ids := make([]string, 0, len(nodes))
|
||||
nodeids := make(map[string][]*Node)
|
||||
|
||||
@@ -348,6 +348,10 @@ func (pq *PetQuery) sqlAll(ctx context.Context) ([]*Pet, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
if query := pq.withTeam; query != nil {
|
||||
ids := make([]string, 0, len(nodes))
|
||||
nodeids := make(map[string][]*Pet)
|
||||
|
||||
@@ -291,6 +291,10 @@ func (sq *SpecQuery) sqlAll(ctx context.Context) ([]*Spec, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
if query := sq.withCard; query != nil {
|
||||
fks := make([]driver.Value, 0, len(nodes))
|
||||
ids := make(map[string]*Spec, len(nodes))
|
||||
|
||||
@@ -569,6 +569,10 @@ func (uq *UserQuery) sqlAll(ctx context.Context) ([]*User, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
if query := uq.withCard; query != nil {
|
||||
fks := make([]driver.Value, 0, len(nodes))
|
||||
nodeids := make(map[string]*User)
|
||||
|
||||
@@ -372,6 +372,10 @@ func (uq *UserQuery) sqlAll(ctx context.Context) ([]*User, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
if query := uq.withSpouse; query != nil {
|
||||
ids := make([]uint64, 0, len(nodes))
|
||||
nodeids := make(map[uint64][]*User)
|
||||
|
||||
@@ -286,6 +286,10 @@ func (uq *UserQuery) sqlAll(ctx context.Context) ([]*User, error) {
|
||||
if err := sqlgraph.QueryNodes(ctx, uq.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -300,6 +300,10 @@ func (cq *CarQuery) sqlAll(ctx context.Context) ([]*Car, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
if query := cq.withOwner; query != nil {
|
||||
ids := make([]int, 0, len(nodes))
|
||||
nodeids := make(map[int][]*Car)
|
||||
|
||||
@@ -397,6 +397,10 @@ func (uq *UserQuery) sqlAll(ctx context.Context) ([]*User, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
if query := uq.withParent; query != nil {
|
||||
ids := make([]int, 0, len(nodes))
|
||||
nodeids := make(map[int][]*User)
|
||||
|
||||
@@ -300,6 +300,10 @@ func (cq *CarQuery) sqlAll(ctx context.Context) ([]*Car, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
if query := cq.withOwner; query != nil {
|
||||
ids := make([]int, 0, len(nodes))
|
||||
nodeids := make(map[int][]*Car)
|
||||
|
||||
@@ -262,6 +262,10 @@ func (gq *GroupQuery) sqlAll(ctx context.Context) ([]*Group, error) {
|
||||
if err := sqlgraph.QueryNodes(ctx, gq.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -262,6 +262,10 @@ func (pq *PetQuery) sqlAll(ctx context.Context) ([]*Pet, error) {
|
||||
if err := sqlgraph.QueryNodes(ctx, pq.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -314,6 +314,10 @@ func (uq *UserQuery) sqlAll(ctx context.Context) ([]*User, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
if query := uq.withCar; query != nil {
|
||||
fks := make([]driver.Value, 0, len(nodes))
|
||||
nodeids := make(map[int]*User)
|
||||
|
||||
@@ -286,6 +286,10 @@ func (gq *GroupQuery) sqlAll(ctx context.Context) ([]*Group, error) {
|
||||
if err := sqlgraph.QueryNodes(ctx, gq.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -324,6 +324,10 @@ func (pq *PetQuery) sqlAll(ctx context.Context) ([]*Pet, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
if query := pq.withOwner; query != nil {
|
||||
ids := make([]int, 0, len(nodes))
|
||||
nodeids := make(map[int][]*Pet)
|
||||
|
||||
@@ -338,6 +338,10 @@ func (uq *UserQuery) sqlAll(ctx context.Context) ([]*User, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
if query := uq.withPets; query != nil {
|
||||
fks := make([]driver.Value, 0, len(nodes))
|
||||
nodeids := make(map[int]*User)
|
||||
|
||||
Reference in New Issue
Block a user