beuzeuh
beuzeuh9mo ago

Query relational data: Get related data field

Hello Support, Hope you can help with the following case. Let's say I have 2 tables, Users and Roles. Users: {id, name, role_id) Roles: {id, name} If I use a query to retrieve the list of users by writing this: export const getUsers = query({ args: {}, handler: async (ctx) => { return await ctx.db.query("Users").collect(); }, }); It will retrieve me something like this: { id: "userId1" name: "John Doe" roleId: "roleId1" } My question is, instead of showing the id of the roleId, How can I query the role table at the same time and retrieve the name of the role instead of the Role Id? What I want to have when calling the getUsers is this: { id: "userId1" name: "John Doe" roleId: "agent" }
1 Reply
lee
lee9mo ago
i think this was resolved in https://discord.com/channels/1019350475847499849/1250951383599943781/1250951383599943781 . If you have follow ups, feel free to ask here or there

Did you find this page helpful?