Skip to content

Commit d3ebd72

Browse files
authored
Add Limitation for Result Client Extension (#6544)
This PR introduces a new Limitation section in the documentation of Prisma Client extensions, specifically addressing the limitation that relation fields are not supported within the Result Client Extension component. This is based on this [discord](https://discord.com/channels/937751382725886062/1319424725767819264) conversation.
1 parent 4999b44 commit d3ebd72

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

content/200-orm/200-prisma-client/300-client-extensions/130-result.mdx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,22 @@ const user = await xprisma.user.findFirstOrThrow({
202202
})
203203
```
204204
In this case, omitting both `password` and `sanitizedPassword` will exclude both from the result as well as prevent the `password` field from being read from the database.
205+
206+
## Limitation
207+
As of now, Prisma Client's result extension component does not support relation fields. This means that you cannot create custom fields or methods based on related models or fields in a relational relationship (e.g., user.posts, post.author). The needs parameter can only reference scalar fields within the same model. Follow [issue #20091 on GitHub](https://github.com/prisma/prisma/issues/20091).
208+
209+
210+
```ts
211+
const prisma = new PrismaClient().$extends({
212+
result: {
213+
user: {
214+
postsCount: {
215+
needs: { posts: true }, // This will not work because posts is a relation field
216+
compute(user) {
217+
return user.posts.length; // Accessing a relation is not allowed
218+
},
219+
},
220+
},
221+
},
222+
})
223+
```

0 commit comments

Comments
 (0)