Marx Low
09/10/2021, 8:04 AM// prisma.schema
Table Post { likes [], ... }
Table User { likes [], ... }
Table Like { userId, postId, ...}
Is there a way for me to create a new likedByUser
Boolean field (Not part of the Post Schema) like this:
prisma.post.findMany({
where: {..}
select: {
likedByUser: { // New annotated field
where: {
likes: [
{ userId: { equals: 2 } },
]
}
}
}
});
Marx Low
09/10/2021, 8:10 AM// 1 query
posts = await prisma.post.findMany(..);
// n queries
forEach post:
const likedByUser = await prisma.like.findFirst({ where: post: post.id, userId: 2 });
Ryan
09/10/2021, 8:16 AMMarx Low
09/10/2021, 8:21 AM