kstulgysK
Convex Community2y ago
19 replies
kstulgys

Why sometime ents one-to-one with optional: true work, sometimes not?

so my schema is this:

    wallets: defineEnt({
      privateKey: v.string(),
    })
      .edge("balance", { optional: true })
      .edge("user")
      .edge("store"),

    balances: defineEnt({
      balance: v.any() as BalanceMap,
    })
      .edge("wallet")
      .edge("store")
      .edge("user"),


I first create wallet then I create balance

    // create wallet
    const walletId = await ctx.db.insert("wallets", {
      privateKey: wallet.privateKey,
      userId: ctx.userId,
      storeId,
    });

    // create balance
    const balanceId = await ctx.db.insert("balances", {
      walletId,
      balance: initialBalance,
      userId: ctx.userId,
      storeId,
    });

    // connect balance to the wallet
    await ctx.db.patch(walletId, { balanceId }); 

// ❌ this is where ts and console is not happy. no balanceId field on wallet table, but walletId field on balance seem to be fine


In other cases I also use this approach with optional: true and it seem to work fine
Was this page helpful?