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

[Bug] Prisma mutations broken when generating tables owned by the user #202

Open
bennet-dev opened this issue Jul 3, 2024 · 0 comments · May be fixed by #203
Open

[Bug] Prisma mutations broken when generating tables owned by the user #202

bennet-dev opened this issue Jul 3, 2024 · 0 comments · May be fixed by #203
Assignees
Labels
bug Something isn't working

Comments

@bennet-dev
Copy link

Config File
{
"hasSrc": true,
"packages": [
"clerk",
"prisma",
"shadcn-ui"
],
"preferredPackageManager": "npm",
"t3": false,
"alias": "@",
"analytics": true,
"rootPath": "src/",
"componentLib": "shadcn-ui",
"orm": "prisma",
"driver": "pg",
"auth": "clerk"
}

Describe the bug
Currently the generator methods for Prisma (generatePrismaDeleteMutation & generatePrismaUpdateMutation), when including User scoping, scaffolds invalid Prisma calls. This happens with

https://github.com/nicoalbanese/kirimase/blame/bb5b0f8e7056505343f7d7813b3d7189bd540c1d/src/commands/generate/generators/model/mutations/generators.ts#L267

export const deleteProduct = async (id: ProductId) => {
  const { session } = await getUserAuth();
  const { id: productId } = productIdSchema.parse({ id });
  try {
    const p = await db.product.delete({ where: { id: productId, userId: session?.user.id! }})
    return { product: p };
  } catch (err) {
    const message = (err as Error).message ?? "Error, please try again";
    console.error(message);
    throw { error: message };
  }
};

v.s.

export const deleteProduct = async (id: ProductId) => {
  const { session } = await getUserAuth();
  const { id: productId } = productIdSchema.parse({ id });
  try {
    const p = await db.product.deleteMany({ where: { id: productId, userId: session?.user.id! }})
    return { product: p };
  } catch (err) {
    const message = (err as Error).message ?? "Error, please try again";
    console.error(message);
    throw { error: message };
  }
};

To Reproduce
Steps to reproduce the behavior:

  1. Generate a Model/View/Controller where the Entity belongs to the user.
  2. In the UI create a record.
  3. In the UI, try to edit or delete the a record that belongs to a user.

Expected behavior
The record should successfully update/delete.

Desktop (please complete the following information):

  • OS: MacOS Sonoma
  • Browser Chrome
  • Version 14.5

Additional context
Discussion in Prisma Github.
When the entity belongs to the user, the generator should use deleteMany/updateMany instead of delete/update.

@bennet-dev bennet-dev added the bug Something isn't working label Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants