Hey! I'm looking to do a REST query like
/api/ticket/${qs.stringify(
{
where: {
user: {
equals: currentUser.id,
},
},
sort: 'event.startsAt',
depth: 1, // get event data too
},
{ addQueryPrefix: true }
)}
But it doesn't seem like sorting by a relationship's nested field is possible. So I've gone with a frontend .sort() after querying instead
Just want to confirm that my understanding is correct here (we can't sort by a related doc's field)
@allannnc I'm not sure about doing this with builtins, but it may exist. Alternatively, you could add an entry to the collections "endpoints" array so that you can manually sort the data and send it back
Thanks for the reply! I think I'll stick with the frontend sort as it ends up being the same amount of work anyway
That's fair! If it were a large amount of items, I would say it's faster on the backend, otherwise a frontend sort works!
Star
Discord
online
Get dedicated engineering support directly from the Payload team.