Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

278
Vistas
Prisma Reading data - is there a better way to read nested data?

I currently need to pull lots of nested data to format into a JavaScript object to send into a chart as the data, I am currently allowing ten nested deep, but there might be some cases when this just keeps on going.

I'm wondering if there is a better way to pull out data like this, I couldn't see anything in the docs, for pulling infinitely or dynamically nested data through the relationships.

This is what I currently have for example:

const [result] = await prisma.company.findMany({
  where: {
    users: {
      some: {
        email: {
          contains: session.user.email,
        },
      },
    },
  },
  select: {
    name: true,
    users: true,
    id: true,
    profiles: {
      select: {
        id: true,
        name: true,
        image: true,
        category: {
          select: { name: true },
        },
        children: {
          select: {
            id: true,
            name: true,
            image: true,
            category: {
              select: { name: true },
            },
            children: {
              select: {
                id: true,
                name: true,
                image: true,
                category: {
                  select: { name: true },
                },
                children: {
                  select: {
                    id: true,
                    name: true,
                    image: true,
                    category: {
                      select: { name: true },
                    },
                    children: {
                      select: {
                        id: true,
                        name: true,
                        image: true,
                        category: {
                          select: { name: true },
                        },
                        children: {
                          select: {
                            id: true,
                            name: true,
                            image: true,
                            category: {
                              select: { name: true },
                            },
                          },
                        },
                      },
                    },
                  },
                },
              },
            },
          },
        },
      },
    },
  },
});
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Have you considered using the include statement instead of select? It automatically fetches all non-relation fields, so you just have to manually specify the relation fields. The nested reads section in the prisma docs also contains a lot of examples for this.

In general, if you don't need granular control over which fields of the model get returned from the query, include is the way to go.

Please check out my answer to a very similar question. I think you might find that solution relevant to your use-case.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda