Description
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
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:
- Generate a Model/View/Controller where the Entity belongs to the user.
- In the UI create a record.
- 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