Title
f

Fergus Meiklejohn

02/07/2022, 4:08 AM
If a Prisma query returns many rows it returns an object:
{0: {}, 1: {}, 2: {} etc...}
Has there been discussion about returning an array instead? An array would be more useful than an object whose keys are just the position in an array anyway. We can get the array with Object.values I know but still it seems like an unnecessary step..
k

ksuh

02/07/2022, 4:31 AM
If you are referring to
findMany
, it does not return an object. It is an array. https://www.prisma.io/docs/reference/api-reference/prisma-client-reference#findmany
f

Fergus Meiklejohn

02/07/2022, 4:37 AM
If there is a join query like in this thread, my comment has many replies, they are returned as an object
k

ksuh

02/07/2022, 4:40 AM
perhaps you could provide a code snippet of your query using prisma.
f

Fergus Meiklejohn

02/07/2022, 4:45 AM
yeah sure!
await db.chatRoom.findUnique({
  where: { id: "123456789" },
  include: {
    comments: {
      select: {
        insertedAt: true,
        id: true,
        commentText: true,
        user: true,
        replies: {
          select: {
            insertedAt: true,
            id: true,
            commentText: true,
            user: true,
            replies: true,
          },
        },
      },
    },
  },
});
Same issue when I use a join table for (eg) users and organisations. The prisma schema shows an array, the prisma query for user with organisation returns an object: {0: {}}`. I'm having to go through my query responses to clean them up. I wanted to discuss this here first, I'm thinking perhaps this should be an issue on the repo.
n

nikolasburk

02/07/2022, 9:13 AM
Hey Fergus 👋 thanks for raising this. Something seems fishy here 🤔 Prisma should certainly return arrays in these situations. Can you maybe open up a new GitHub issue and ideally provide a standalone reproduction of the issue so that our Engineering team can look into this?