headpie
headpie
PPrisma
Created by headpie on 12/23/2024 in #help-and-questions
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?
4 replies