October 22, 2024
Chicago 12, Melborne City, USA
javascript

Prisma returning unwanted count


Doing the query below the Prisma result returns a unwanted "count" property into likes object. We can see that the _count operator is not used anywhere.
I tried to change the count to false, but it keeps being returned. How can I disable this?

const user = await prisma.user.findUnique({
      where: {
        id: id
      },
      select: {
        id: true,
        username: true,
        posts: {
          omit: {
            userId: true,
          },
          include: {
            comments: {
              select: {
                id: true,
                user: {
                  select: {
                    id: true,
                    username: true,
                    profilePicture: true,
                  }
                },
                text: true
              }
            },
            likes: {
              select: {
                id: true,
                user: {
                  select: {
                    id: true,
                    username: true,
                    profilePicture: true,
                  }
                }
              }
            }
          }
        }
      }
    })

[
    {
        "id": "cm29icdzk0003ljs4nbmvor5u",
        "user": {
            "id": "cm29ibc6h0001ljs4gr73xl6q",
            "username": "caio"
        },
        "picture": "4cdd32cc-d2b3-4c26-9a1b-0f050ee7d48c",
        "comments": [
            {
                "id": "cm2bbusv200002s8r14mk3s20",
                "text": "abc\n",
                "user": {
                    "id": "cm29ibc6h0001ljs4gr73xl6q",
                    "username": "caio",
                    "profilePicture": "764d4cec-79e0-4aef-a7b7-af1c2642e37f"
                }
            },
            {
                "id": "cm2bbvgwi00012s8rkkyvfgan",
                "text": "abc\n\n",
                "user": {
                    "id": "cm29ibc6h0001ljs4gr73xl6q",
                    "username": "caio",
                    "profilePicture": "764d4cec-79e0-4aef-a7b7-af1c2642e37f"
                }
            },
            {
                "id": "cm2bch34x00022s8rktrccf49",
                "text": "testando\n",
                "user": {
                    "id": "cm29ibhas0002ljs4s50b4yoc",
                    "username": "maria",
                    "profilePicture": null
                }
            }
        ],
        "likes": {
            "users": [
                {
                    "id": "cm29ibc6h0001ljs4gr73xl6q",
                    "username": "caio",
                    "profilePicture": "764d4cec-79e0-4aef-a7b7-af1c2642e37f"
                },
                {
                    "id": "cm29ibhas0002ljs4s50b4yoc",
                    "username": "maria",
                    "profilePicture": null
                },
                {
                    "id": "cm29il7qe0004ljs4nujwiykh",
                    "username": "gerson",
                    "profilePicture": null
                }
            ],
            "count": 3
        }
    }
]



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video