[Ents]: Ordering on Edge

Hello all,

I have a question which in short is whether (or rather how) it's possible to order the query of many:many edges on the other end of the edge using convex-ents.

I have user ents which can "attend" events ents - i.e. many:many relationship. I want to query the events a single user is attending and in the same query order the retrieved events based on the start date of the events (in the db as a string, like 2025-01-24T12:30:00.000+01:00) as follows:

await table("users")
  .getX(userId)
  .edge("attendingEvents")
  .order("asc", "by_startdate");


The events schema contains an index for "startdate". But my retrieved results are never ordered by the startdate.

My current solution looks like this:

    const events = await table("users")
      .getX(userId)
      .edge("attendingEvents");

    return events
       .filter(({ startdate }) => startdate >= today.toISOString())
       .sort((a, b) => a.startdate.localeCompare(b.startdate))
       .splice(0, take);


Perhaps there is a more efficient way to do this since I'm filtering out the results that have a startdate in the past anyway.

Any help would be highly appreciated πŸ™‚
Was this page helpful?