stevanfreeborn
stevanfreeborn17mo ago

Joining and Paging

Is there an established pattern for both joining data and paging through it using the built-in paginated queries? I can see how you could implement it yourself in the typical pattern of passing page parameters to a query that does the joining, but the usability of the paginated queries is really nice.
2 Replies
sshader
sshader17mo ago
Re: joining in general, https://stack.convex.dev/functional-relationships-helpers might be an interesting read -- it has several helpers for accessing relational data I'm not sure if there's an established best practice for joining and paginating, but I believe you can map over the results of a paginated query (i.e. to follow a one to one reference / one to many reference) (https://docs.convex.dev/database/pagination#writing-paginated-query-functions) Some current limitations -- I believe there can only be one db.query(...).paginate(...) per query function, and we only support paginating based on an index, so any properties you want to sort on would need to be in the same table so they can all be included in an index. (I'm not sure if I'm answering your question, so if you have a concrete example you wouldn't mind sharing, that would be helpful to me)
Functional Relationships: Helpers
In this post, we’ll look at some helper functions to help write code to traverse relationships in a readable, predictable, and debuggable way.
stevanfreeborn
stevanfreebornOP17mo ago
@sshader thank you! I didn't realize that you could actually work with the page of results before returning the page. I think I can do what I want if I can figure that out. If not I'll come back with some concrete examples of what is not working for me. Really appreciate you helping me 🙏🏻

Did you find this page helpful?