igor9silva
igor9silva2mo ago

__tableName on IDs

is __tableName supposed to be undefined on client-side? I have a field that can be one of two possible kinds of Ids, want to check which one it is in runtime
No description
1 Reply
sshader
sshader2mo ago
IDs are strings at runtime (both on the client and the server), so the __tableName property is always undefined at runtime. It exists in the type so that TypeScript can be more helpful. If you want to differentiate between two different ID types at runtime, you have two options -- ctx.db.normalizeId("yourTable", id), available in queries + mutations which will return the ID only if it's a valid ID for that table, or storing the table name yourself (e.g. author: { table: "users", id: Id<"users"> } | { table: "aiAgents", id: Id<"aiAgents"> }) (relevant docs which touch on a little of this: https://docs.convex.dev/database/document-ids)

Did you find this page helpful?