Closed kristinlindquist closed 1 year ago
I am working on this issue. Hopefully, we will have a PR soon
I find out that z.union
is responsible for this problem. As we are wrapping the schemas inside z.union
, we can not use multiple fields inside it. So in general, this problem will arise not only for deleteMany and createMany
but also for any fields if we want to use multiple fields.
@omar-dulaimi, Could you please tell us why we need to wrap the schemas with z.union
if the fields contain connectOrCreate:
or connect:
inside the addFinalWrappers
function during generating object schemas? What is the insight of it? If I remove this logic and simply wrap the whole schemas with z.object
, then I am not getting any issues.
@Shahidul1004 I remember it was for an old bug, but I guess it was solved with the later changes. I'll give your changes a try and see if it works well.
Bug description
In order to do a nested upsert/set of N-to-Many entities, one needs to tell prisma to do something like this:
(e.g. https://github.com/prisma/prisma/issues/2255#issuecomment-683811551)
The deleteMany removes all the nested entities, and then the createMany creates all of them again. While this doesn't seem to be terribly efficient, I don't know of another way to handle a nested N-to-Many write in which you may be adding and updating existing entities.
...But, this generator prevents one from specifying more than one verb in a given data object by outputting validation like this:
which is a union of single attribute objects. The resultant validation error is something like this:
How to reproduce
Attempt to use more than one verb for a nested entity, e.g. deleteMany and createMany.
Expected behavior
Verbs like deleteMany and createMany can be used together.
Prisma information
n/a
Environment & setup
Prisma Version