doc/md: add example on how to group-by an edge

This commit is contained in:
Ariel Mashraki
2021-04-19 14:14:29 +03:00
committed by Ariel Mashraki
parent a51c50f6a3
commit 2bfb34fe82
2 changed files with 37 additions and 0 deletions

View File

@@ -804,6 +804,8 @@ func Relation(t *testing.T, client *ent.Client) {
Where(user.IDIn(foo.ID, bar.ID)).
GroupBy(user.FieldID, user.FieldName).
Aggregate(func(s *entsql.Selector) string {
// Join with pet table and calculate the
// average age of the pets of each user.
t := entsql.Table(pet.Table)
s.Join(t).On(s.C(user.FieldID), t.C(pet.OwnerColumn))
return entsql.As(entsql.Avg(t.C(pet.FieldAge)), "average")