Skip to content

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

Open
@bennet-dev

Description

@bennet-dev

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions