P
Prisma2mo ago
headpie

relation-queries-docs

Hi, I'm new, and I think I'm misunderstanding something in the docs, on this page: https://www.prisma.io/docs/orm/prisma-client/queries/relation-queries#filter-a-list-of-relations It states, "... the following query returns all users and a list of titles of the unpublished posts associated with each user:"
const result = await prisma.user.findFirst({
select: {
posts: {
where: {
published: false,
},
orderBy: {
title: 'asc',
},
select: {
title: true,
},
},
},
})
const result = await prisma.user.findFirst({
select: {
posts: {
where: {
published: false,
},
orderBy: {
title: 'asc',
},
select: {
title: true,
},
},
},
})
But this does not give me all users, it gives me one user (most recently created maybe?), with only the property "posts", the unpublished posts. Furthermore, the docs say, "You can also write the same query using include as follows:"
const result = await prisma.user.findFirst({
include: {
posts: {
where: {
published: false,
},
orderBy: {
title: 'asc',
},
},
},
})
const result = await prisma.user.findFirst({
include: {
posts: {
where: {
published: false,
},
orderBy: {
title: 'asc',
},
},
},
})
, but this gives me output different from the previous code. It gives me a different user and more properties. Am I misunderstanding the docs or does this section need rewriting?
1 Reply
Nurul
Nurul2mo ago
Hello @headpie 👋 Thank you for highlighting this. Your observation is correct! The docs are incorrect here, findFirst returns only one record and not all records. I am opening a docs PR to fix this 🙏 This is fixed now! Thank you for reporting 🙌

Did you find this page helpful?