Using OR in connectOrCreate
I want to connect to an image if imageId is defined. If not, I want to connect to an image with a matching fileStorageObjectId. If it is not found I want to create a new image.
I get the error: Type '{ OR: ({ id: string | undefined; } | { fileStorageObjectId: string; })[]; }' is missing the following properties from type '{ fileStorageObjectId: string; id: string; entryId: string; }': fileStorageObjectId, id, entryId ts (2322) [511, 11]
2 Replies
Hello @monkeysjump 👋
Prisma expects the where clause in
connectOrCreate
to contain unique fields that can identify a single record. Your current approach using OR in the where clause is not directly supported by Prisma's connectOrCreate operation. The where clause should typically contain a single unique identifier.
To achieve what you're trying to do, you might need to split this operation into multiple queries
1. Try to find an existing image based on imageId or fileStorageObjectId
2. If found, connect to it.
3. If not found, create a new image.Got it. Thank you!!