PrismaP
Prisma16mo ago
1 reply
Eddie Jaoude

Custom method in a model, gives a "not found" error

I am trying to create a custom method in my model, but when I try to use it, it says not a function. I am confused by the docs that I quoted below as the works/not works are the same code?

In the above example, prisma.user.signUp works, but prisma.user.signUp does not, because the original prisma is not modified.
https://www.prisma.io/docs/orm/prisma-client/client-extensions/model#example

Here is my usage in my NextJS project:

Prisma client with custom method


new PrismaClient().$extends({
    model: {
      utm: {
        async totalClicks(utmId: string) {
          const utmStats = await prisma.utmStats.findMany({
            where: { utmId },
          });
          return utmStats.reduce((a, b) => a + b.clicks, 0) || 0;
        },
      },
    },
  });


Usage


const utm = await prisma.utm.findUnique({ ... });
const totalClicks = await utm.totalClicks(utm.id); // ERROR: Property 'totalClicks' does not exist


I tried "generate" also, but no change.

Any help appreciated
Was this page helpful?