PrismaP
Prisma10mo ago
7 replies
vanHessler

Prisma Select TypeError

ok - my issue might be unrelated:

This works:
function manyFoo(select?: Prisma.fooSelect) {
  const builtSelect = {
    ...select,
    id: true,
    name: true,
    Bar: {
      select: {
        id: true,
        name: true,
        Baz: {
          select: {
            id: true,
            name: true
          }
        }
      }
    }
  } as const satisfies Prisma.fooSelect;
  // find many foo
  const results = await prisma.foo.findMany({
    select: builtSelect,
  });
  return results.map((foo) => {
    return {
      ...foo,
      bar: foo.Bar.name,
      baz: foo.Bar.Baz.name,
    };
  });
}

This does not:
function manyFoo(select?: Prisma.fooSelect) {
  const builtSelect = {
    id: true,
    name: true,
    Bar: {
      select: {
        id: true,
        name: true,
        Baz: {
          select: {
            id: true,
            name: true,
          },
        },
      },
    },
    ...select,
  } as const satisfies Prisma.fooSelect;


  // find many foo
  const results = await prisma.foo.findMany({
    select: builtSelect,
  });
  return results.map((foo) => {
    return {
      ...foo,
      bar: foo.Bar.name,
      baz: foo.Bar.Baz.name, //<-- ERROR HERE
    };
  });
}

When i move the select param to the bottom after a multiple nested relation lookup, it throws errors for the nested relation's properties. Why?
Was this page helpful?