Retrieving many-to-many joins
Hey, is there a way to just select so fields to retrieve? Because I querying a table taht contains the userId and the teamId, and I would like to just get the teamId's in order to then query the data of those ID and return it. (In order to show the user all the teams where its a member).
6 Replies
ctx.db.query()/.get()
will always return entire records, no way to limit to specific fields. You're describing a many-to-many relationship, here's how to handle it Convex:
There are a number of stack articles and helpers for relationships in Convex, here's more on the basic many-to-many pattern: https://stack.convex.dev/relationship-structures-let-s-talk-about-schemas#relationship-table-scalableRelationship Structures: Let's Talk About Schemas
In this post we’ll look at some patterns for structuring relationships in the Convex database.
This is how I did it in my application
GitHub
convex_feedit/convex/users.ts at master · trace2798/convex_feedit
PostIT: Share it with your group. This is a web application where users can create group and post. - trace2798/convex_feedit
That application is currently deployed you can see the outcome here
https://postit-omega.vercel.app/u/kh764btfffnsrpm0s6c5593yyh6n8456
postit-omega.vercel.app
PostIT - Share with your group and the world
A fullstack web application for Convex Zero to One hackathon
@Llabe this thread will work
Perfect
Thankss! I'll give it a look now 🙂