[SOLVED] Hide permanently password attributes from Prisma Database Query

Issue

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.

Solution

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

Answered By – Nurul Sundarani

Answer Checked By – David Marino (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *