New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prisma many-to-many query not properly structuring data #15643
Comments
Hey @demacericcardo, could you please share the following with us?
That would be helpful for us to be able to look into it. Thanks! |
My schema: `generator client { datasource db { model User { username String @unique name String roles Role[] model Event { eventDate DateTime users UsersOnEvents[] model UsersOnEvents { @@id([userId, eventId]) enum Role { Node version: 16.16.0 Prisma version: The code is the same I already posted:
|
Thanks. The result data/structure seems expected to me, why is it unexpected for you? |
I was expecting the query not including the data from the many to many table but just an array of the referenced users, how can i do that? if there's a way |
If I understood well, you want the nested result as a top result? That's not possible. You'd need to get it yourself by accessing the nested properties. |
Ok, no problem. Thank you |
What's the best way to achieve that when quering multiple times the same field with a many-to-many relationship? @millsp I'm refering to this block of code
|
Yeah i was about to cycle the data and restructure the object before using it, my issue was about if there was a better way with just a single query. |
Middleware can do that. However, be aware that you'd lose type-safety. That might be ok if that isn't a requirement. |
I can't get the data from a many to many relation in a proper way. I got the relation: USER-EVENT
Prisma query:
await this.prisma.event.findUnique({ where: { id: eventId }, include: { users: { select: { user: true } } } })
The data appears double nested:
The text was updated successfully, but these errors were encountered: