How to sort a supabase array based on a each object's subobject

Basically I’m trying to create a list of questions that people can upvote, and I want the questions with the most vote to be at the top of the list.

In supabase I have a posts table and a post_reactions table (so I can track which users react to which posts). A bit simplified but I have

  • post table with id,post
  • post_reaction table with id,user_id,post_id

I’m querying post with:

id,
post,
user_post_reaction: id(count)

This function works, but given the graphql nature of supabase the count is a sub object, so I access like

query.user_post_reaction[0].count

I cant find a way to path into the sub objects to sort the parent array… either on the query or on the front end collection

I tried mapping to a new table but am getting an undefined error for the count

map(query,“id”,“post”,“user_post_reaction[0].count”)

I can create a postgres function if I need to, just seems like I’m missing something small and obvious

I’d suggest making this on the Supabase side, or use the new Workflow Actions, this Collections interface is old, and it doesn’t support filtering by nested properties. You can do this with the new Workflow Actions.

Ok I’m still not getting the workflow behavior to work…

Just going to write a postgres function

ok have the postgres function working, will just air on the side of doing that instead of query filters