TripleSpeederT
Convex Community3y ago
14 replies
TripleSpeeder

Is there a way to get the object type from a db.get result?

I want to create a generic Like table like this:
like: defineTable({
    userId: v.id("users"),
    targetId: v.union(
      v.id("bike"),
      v.id("part"),
      v.id("event"),
    );,
  })

So i can use the same table for storing likes to bikes, parts or events. This works fine, but I'm struggling with one aspect:
I would like to create a page where a users sees all objects he has liked. I can get the actual target object (bike, part or event) of a like with this query:
const like = await ctx.db.get(likeId);
return await ctx.db.get(like.targetId);

Problem is I don't know the actual type of the target object. And I need this information to display accordingly in the frontend. Is there some generic/built-in way to get the actual type of the get response?
Was this page helpful?