How to implement pagination with join and filtering
Given that I have these 2 tables that describes a 1-to-many relationship: "a user can be member of 1 or many groups"
What would be the convex way to implement the following
paginated
query: get groups of user A (each page has 10 items)
. This is (a naive) equivalent SQL
query:
3 Replies
Thanks for posting in <#1088161997662724167>.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.
- Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
- Use search.convex.dev to search Docs, Stack, and Discord all at once.
- Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI.
- Avoid tagging staff unless specifically instructed.
Thank you!
For this you need to:
1. Get the members with a given user id / group ID
2. Grab the associated group info
So if you'd want to fetch the members by
user_id
you'd want an index:
And you can then paginate the members by it:
And join in the group data (here just adding the member id, but could also add other user/ member data):
Then return the paginated data:
THanks @ian for this answer