How to efficiently order a foreign key based collection

#1

Let’s suppose I have a type Child and a type Parent linked like this

Child {

parent: Parent
}

Parent {

children: [Child] (parent)
}

I would like to order the children for a given parent based on the field number defined on Child. How do I do this?

0 Likes

#2

Just add the db annotation above the field children in Parent:

@db(order=‘number’)
children: [Child] (parent)

It would also be a good idea to add a db index on the type Child as follows:
@db(index=[“parent, number”])

so that the Child table is order by parent and number.

0 Likes