How would you structure this schema?
I have the following schema:
Note I want to be able to list all the canvases that a user is a member of but I cant.
Im guessing I have to reverse this structure and have a "canvasMembers" table that records the
userId
and canvasId
and then index and query that first then join to get the canvases?
Just checking incase there is a better way.4 Replies
Yep. A junction table is the right call here. https://stack.convex.dev/relationship-structures-let-s-talk-about-schemas
Relationship Structures: Let's Talk About Schemas
In this post we’ll look at some patterns for structuring relationships in the Convex database.
Very similar to traditional databases. That way you can create the indexes you want. To quickly produce that list of canvases per member.
Many-to-many.
okay.. so just while I have you jamie.
It would look something like this:
Wouldnt this
Promise.all(
cause me a high number of db reads from my quota?
I guess as you say, if im concerned about that then I should create a many-to-many table to manage thatIt should be okay. Also, find a lot of useful utility functions here for parallel/high performance reference traversal: https://stack.convex.dev/functional-relationships-helpers
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.