kunga_tashi
kunga_tashi12mo ago

One-to-many relationships

I am already using a one to many relationship if I am not wrong. I have projects table and a documents table where one project can have multiple documents, so I am storing the documentIds as an array.
No description
3 Replies
erquhart
erquhart12mo ago
You could get rid of the documents array entirely, and use documents.project to join a project to it's documents. In a one-to-many, the one doesn't need a direct reference to the many, the many just need a direct reference to the one. You would get a project id and then query all documents that belong to that project.
Abhishek
Abhishek12mo ago
@kunga_tashi this blog post is gem take a look it will clear your doubts 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.
kunga_tashi
kunga_tashiOP12mo ago
@Abhishek @erquhart Thanks you two, Although I read that article, I didn't see the back reference part last time hehe.

Did you find this page helpful?