beuzeuh
CCConvex Community
•Created by beuzeuh on 6/14/2024 in #support-community
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"
}
2 replies