Prisma 2-3 levels deep queries
Hey, I'm building an app, where I need to get "friends of friends" data.
Like for example, I query "target" user friends first and get a list of user IDs. Then I need to query every user ID in that list and get the same structured list, but of all the friends of friends combined.
How can I do this?
11 Replies
Won't something like this work
const user = await prisma.user.findFirst({
include: {
friends: {
select: {
friends: true,
},
},
},
})
yeah, yeah it does work. splendid.
Although I receive a list with full user objects with this query. Additional 'select' inside 'friends' doesn't seem to be working.
Its include: {}
Try that
Nested include
tried all combinations of the above, same result. Guess I am to resort to .map()
Wierd ive seen nested includes before
Probably mapping through will do the job
Not sure if nested select will do the job so they can choose what they want from the model
At the end if you really want to select specific data u should use pure sql or like a orm with low level support or you can map through it but i dont know at what performance cost?.
drizzle?.
Make sure your schema is correctly defined. You can either use self relations or a separate table to manage the friends. If the schema is correctly defined, you should be able to perform the nested includes to get friends of friends
⏫
It is self relation but they want the self relations of self relation
Friends of friends
Not sure if with nested select they can select only the needed props