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
Sybatron
Sybatron2y ago
Won't something like this work const user = await prisma.user.findFirst({ include: { friends: { select: { friends: true, }, }, }, })
.traevelliath
.traevelliathOP2y ago
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.
Maj
Maj2y ago
Its include: {} Try that Nested include
.traevelliath
.traevelliathOP2y ago
tried all combinations of the above, same result. Guess I am to resort to .map()
Maj
Maj2y ago
Wierd ive seen nested includes before Probably mapping through will do the job
Sybatron
Sybatron2y ago
Not sure if nested select will do the job so they can choose what they want from the model
Maj
Maj2y ago
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?.
Sebastian
Sebastian2y ago
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
Maj
Maj2y ago
Sybatron
Sybatron2y ago
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
Want results from more Discord servers?
Add your server