How can I grab an all linked ents from a linked ent

Hi, this is my schema:

const schema = defineEntSchema({
  privateChats: defineEnt({})
    .field("support", v.boolean(), { default: false })
    .edges("users", { to: "users" }),
  users: defineEnt({})
    .field("clerkId", v.string(), { unique: true })
    .field("username", v.string(), { unique: true })
    .edges("chats", { to: "privateChats" }),
});


I have a user identifier. Now I want to grab every chat of this user and the information about the others in the chat. How can I do that?

I tried something like that, but it obviously did not work:

    // Retrieve the user entity by its ID
    const user = await ctx
      .table("users")
      .getX("clerkId", identity.tokenIdentifier);

    // Traverse the edge to get the chats linked to the user
    const chats = await user.edgeX("chats").docs();

    return chats.map(async (chat) => ({
      ...chat,
      users: await chat.edge("users"),
    }));
Was this page helpful?