Home > other >  Hide permanently password attributes from Prisma Database Query
Hide permanently password attributes from Prisma Database Query

Time:03-22

I want to make a database request to get all the jobs linking with the User's data. How can I remove the attribute of the user's password being fetched?

    const job = await prisma.jobs.findMany({
      where: {
        id: Number(id),
      },
   
      include: {
        User: true, // I want to hide the user s password
      },
    });

I tried this Github Page, but had no success.

CodePudding user response:

You can achieve this by following query:

const job = await prisma.jobs.findMany({
  where: {
        id: Number(id),
  },
  // Returns all job fields
  include: {
    User: {
      select: {
        name: true,
        // Every other user fields except password
      },
    },
  },
})

Here is the reference section which will be helpful: Include with select

  • Related