SpicedS
Convex Community2y ago
2 replies
Spiced

How can i access a one to many relationship.

export const getByIdInfo = query({
  args: {
    diagramId: v.optional(v.id("diagrams")),
  },
  handler: async (ctx, args) => {
    const identity = await ctx.auth.getUserIdentity();

    if (!args.diagramId) {
      return; // No diagramId provided
    }

    const document = await ctx.db.get(args.diagramId);

    if (!document) {
      throw new Error("Document not found or unauthorized access");
    }

    if (!identity || document.userId !== identity.subject) {
      throw new Error("Unauthorized access");
    }

    return { ...document }; // Return the document information
  },
});


this is my api, the diagram table has a databaseTypeId, which in turn has a seperate relationship with a table called databasetypes. How can i access it through this relationship and pull the name of the id?
Was this page helpful?