Skip to content

Incompatible to Fluent API of Prisma #9

@dahaupt

Description

@dahaupt

First of all, thanks a lot for this extension, which is really crucial in our project as part of a multi-tenant validation.

We ran into an issue related to the usage of the Fluent API of Prisma.

Example schema:

model Parent {
  id    Int     @id @default(autoincrement())
  child Child[]
}

model Child {
  id       Int     @id @default(autoincrement())
  child    String
  parent   Parent? @relation(fields: [parentId], references: [id])
  parentId Int?
}

Example relation query:

const child = await prisma.parent.findUniqueOrThrow({
    where: {
        id: 1
    }
}).child();

Expected output:

[
  {
    id: 1,
    child: 'Test',
    parentId: 1,
  }
]

Actual output:

[
  {
    id: 1,
    child: null, // <-- Invalid
    parentId: 1,
  }
]

The problem seems to occur only if a field with the same name as the model is used. The (string) value of the field is then replaced with null (related to this operation).

We solved it simply by changing the field name of the relation to the plural form (childs) in order to have a difference to the field name (child).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions