Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

connect should throw if the related record does not exist #528

Open
empz opened this issue Aug 20, 2023 · 1 comment
Open

connect should throw if the related record does not exist #528

empz opened this issue Aug 20, 2023 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@empz
Copy link

empz commented Aug 20, 2023

https://www.prisma.io/docs/reference/api-reference/prisma-client-reference#remarks-16

@morintd morintd added help wanted Extra attention is needed enhancement New feature or request labels Jun 14, 2024
@thw0rted
Copy link

I'm not sure if this is related, but I just tried using a nested createMany to create a reference to a non-existent record through a link table, and Prismock did not throw when I expected it to. I don't have a full repro right now but the gist looks something like this:

Suppose you have models for Order and Item, and a Request model that describes items added to an order. Maybe a Request captures the quantity of a given item requested, a color/size/version, whatever; the point is you have a model that has a one-to-many relation with two other models. For simplicity, let's say submitting an order makes a new Request for each item:

prisma.order.create({
  data: {
    customer: { connect: { id: userId } },
    requests: {
      createMany: {
         data: itemIDs.map(id => ({itemId: id, qty: 1}))
      }
    }
  }
});

This should make a new Request for each number in the itemIDs array. The problem is, what if an unknown item ID is in the array? I expected Prismock to throw in this case, but instead it creates a record with an invalid itemId value, and when you query the result, the linked Item record just comes back as null.

I saw over on #685 that "errors are not yet implemented", so I guess this all falls into the error-handling bucket?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants