#schema error
1 messages · Page 1 of 1 (latest)
I can see you're encountering a schema validation error in your Convex application. Let me explain what's happening.
The Error
The error occurs because the value you're trying to store in the resultIds field doesn't match the validator defined in your schema. Specifically:
Failed to insert or update a document in table "tasks" because it does not match the schema: Value does not match validator.
Path: .resultIds
Value: {0: "ks74yxajz2p02fs3j9w76ezhz57fdvz7"}
Validator: v.array(v.id("workspaceImages"))
The Issue
Looking at your code and the error message, I can identify the problem:
-
Your validator expects
resultIdsto be an array of IDs from the "workspaceImages" table:v.array(v.id("workspaceImages")) -
However, the value being passed is an object with numeric keys instead of an array:
{0: "ks74yxajz2p02fs3j9w76ezhz57fdvz7"} -
Your code shows that
resultsis correctly an array:[ 'ks74yxajz2p02fs3j9w76ezhz57fdvz7' ] -
The issue likely occurs when you call
prismaToConvex(params), which might be transforming your array into an object.
Solution
There are a few ways to fix this:
-
Remove the
prismaToConvextransformation: If this function is converting your arrays to objects, you might need to modify it or bypass it for this field. -
Ensure proper array format: Make sure the value is a proper JavaScript array before saving:
resultIds: Array.isArray(results) ? results : Object.values(results), -
Check your schema: Ensure your schema definition matches what you're trying to store. If you're consistently storing objects instead of arrays, you might need to adjust your schema validator.
Convex enforces schema validation at runtime to ensure data integrity Schema Validation. When you attempt to insert or update a document that doesn't match the schema, Convex will throw an error like the one you're seeing.