'Hide permanently password attributes from Prisma Database Query

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 1:[1]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nurul Sundarani