Benny
11/23/2021, 3:00 PMmodel User {
id String @id
ownership Ownership[]
}
model Ownership {
id String @id @default(cuid())
user User? @relation(fields: [userId], references: [id])
userId String
createdAt DateTime @default(now())
}
When i query a user, i want to return only 1 ownership:
prisma.user.findUnique({
where: {
id: userId,
},
include: {
ownership: {
take: 1,
orderBy: {
createdAt: 'desc',
},
},
},
})
But i want the user.ownership
will be an object, and not array of 1 ownership
element.
i.e
result.ownership = result.ownership[0];
I want to do it for every query for User, so middleware seemed like the best approach but i can see how you can't mutate the return value of the query with middleware.
Any ideas maybe?Ryan
11/23/2021, 3:22 PMBenny
11/23/2021, 3:25 PMRyan
11/24/2021, 4:54 AM