Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatible to Fluent API of Prisma #9

Open
dahaupt opened this issue Mar 18, 2024 · 0 comments · May be fixed by #10
Open

Incompatible to Fluent API of Prisma #9

dahaupt opened this issue Mar 18, 2024 · 0 comments · May be fixed by #10

Comments

@dahaupt
Copy link

dahaupt commented Mar 18, 2024

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).

dahaupt added a commit to dahaupt/prisma-extension-nested-operations that referenced this issue Mar 18, 2024
dahaupt added a commit to dahaupt/prisma-extension-nested-operations that referenced this issue Mar 18, 2024
@dahaupt dahaupt linked a pull request Mar 18, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant