saito200
saito20011mo ago

Validator from schema, including internal fields?

I'm passing full DB records to one of my actions and I'm trying to build the validator After some tinkering it looks like this:
export const myAction = internalAction({
args: {
idea: v.object({ ...myValidator, _id: v.id("myTable") })
},
export const myAction = internalAction({
args: {
idea: v.object({ ...myValidator, _id: v.id("myTable") })
},
I am exporting the validator from the schema similar as described here https://stack.convex.dev/types-cookbook The fact that I have to add the _id manually feels a bit awkward to me, but I need the id to be used as a foreign key Am I doing something weird? Is this simply ok? (the action uses some of the fields of the record to create a record for a different table) What I started looking for originally was like a built-in validator that can be extracted from the schema or somewhere else, similar as you can get the DB record type with Doc<"myTable"> but the equivalent for validators, including internal fields
Types and Validators in TypeScript: A Convex Cookbook
It can be tough to wrangle types to behave how you want them to. Thankfully, Convex was designed to make the experience with types perfect. Learn why ...
1 Reply
Michal Srb
Michal Srb11mo ago
Hey @saito200 , I believe this is a similar question to the one I answered here: https://discord.com/channels/1019350475847499849/1195775711110234153/1195779604145782845

Did you find this page helpful?