mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
doc: add example for edge ordering
This commit is contained in:
committed by
Ariel Mashraki
parent
b2f6834f67
commit
794ca45435
@@ -36,3 +36,16 @@ users, err := client.User.Query().
|
||||
Order(ent.Asc(user.FieldName)).
|
||||
All(ctx)
|
||||
```
|
||||
|
||||
## Edge Ordering
|
||||
|
||||
In order to sort by fields of an edge (relation), start the traversal from the edge (you want to order by),
|
||||
apply the ordering, and then jump to the neighbours (target type).
|
||||
|
||||
The following shows how to order the users by the `"name"` of their `"pets"` in ascending order.
|
||||
```go
|
||||
users, err := client.Pet.Query().
|
||||
Order(ent.Asc(pet.FieldName)).
|
||||
QueryOwner().
|
||||
All(ctx)
|
||||
```
|
||||
Reference in New Issue
Block a user