prismock icon indicating copy to clipboard operation
prismock copied to clipboard

`findFirst` with nested selection into explicit many-to-many table not working

Open electrovir opened this issue 7 months ago • 2 comments

I have a query like this:

const result = await prismaClient.user.findFirst({
    select: {
        id: true,
        name: true,
        manyToManyTable: {
            select: {
                otherRelation: {
                    select: {
                        id: true,
                        name: true,
                    }
                }
            }
        }
    }
})

Where my Prisma schema looks like this:

model User {
    id              Int
    name            String
    manyToManyTable ManyToManyTable[]
}

model ManyToManyTable {
    userId          Int
    otherRelationId Int
    
    otherRelation OtherRelation @relation(fields: [otherRelationId], references: [id])
    user          User          @relation(fields: [userId], references: [id])
}

model OtherRelation {
    id              Int
    name            String
    manyToManyTable ManyToManyTable[]
}

The mentioned query always returns an empty array for result.manyToManyTable, even when I've verified that the data exists.

Is this a known limitation? I didn't see anything obviously relevant in the README. If you need a repro example repo let me know and I'll whip one up.

electrovir avatar Jul 09 '24 23:07 electrovir