If a Prisma query returns many rows it returns an ...
# orm-help
f
If a Prisma query returns many rows it returns an object:
Copy code
{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
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
If there is a join query like in this thread, my comment has many replies, they are returned as an object
k
perhaps you could provide a code snippet of your query using prisma.
f
yeah sure!
Copy code
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
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?