PrismaP
Prisma4mo ago
3 replies
DeathlyNocturnal

Prisma isn't doing joins.

Hi, I have just setup the relation strategy as we would like the ORM to use join queries.

But I have noticed it just won't do a join, even after setting the preview feature and then trying the relationLoadStrategy.

Here is a minifed version:

model rules {
    id          String   @id @db.Char(16)
    name        String   @db.VarChar(255)
    object_id   String   @db.Char(16)
    object      objects  @relation(fields: [object_id], references: [id])
}

model objects {
    id            String    @id @db.Char(16)
    original_id   String?   @db.Char(16)
    rules         rules[]
}


And I am doing:
const rule = await prisma.rules.findFirst({
    relationLoadStrategy: 'join',
    select: {
        name: true,
        object: {
            select: {
                name: true,
            },
        },
    },
});


but I am still seeing this:
prisma:query SELECT `t0`.`id`, `t0`.`name`, `t0`.`object_id`, (SELECT JSON_OBJECT('name', `t1`.`name`) FROM `createdb`.`objects` AS `t1` WHERE `t0`.`object_id` = `t1`.`id` LIMIT ?) AS `object` FROM `createdb`.`rules` AS `t0` LIMIT ?
Query: SELECT `t0`.`id`, `t0`.`name`, `t0`.`object_id`, (SELECT JSON_OBJECT('name', `t1`.`name`) FROM `createdb`.`objects` AS `t1` WHERE `t0`.`object_id` = `t1`.`id` LIMIT ?) AS `object` FROM `createdb`.`rules` AS `t0` LIMIT ?
Params: [1,1]


What is happening? why is it ignoring what I ask it?
Was this page helpful?