#How can I use plain object instead of composite types ?

4 messages · Page 1 of 1 (latest)

mint quail
#

Hi,

We were using Prisma v4.10.0 in ou project and we upgraded to 4.16.0 in order to use the new $extends() features

Problem :
When we updated to 4.16, all of our code broke because now, our mongo's embedded documents are defined as "composite types" with the following struct :

{ objects : {}, scalars: {}, composites: {} }

It's a huge pain because before we had the plain object directly and we could do something like :

const user = await prisma.user.find(); console.log(user.profile.name)

now :

const user = await prisma.user.find(); console.log(user.profile.scalars.name)

Any idea if there is an option to go back to old way ?

hazy yarrowBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

jade chasm
# mint quail Hi, We were using Prisma v4.10.0 in ou project and we upgraded to 4.16.0 in ord...

Hi vmathi Sorry to hear that! You can try to upgrade to a fixed version, v4.16.2-dev.2, which should fix some issues with composites:

npm install @prisma/[email protected] [email protected]

Another option is to try to have explicit type selection by explicitly select the fields you need in your queries:

const user = await prisma.user.find({
  select: {
    profile: {
      select: {
        name: true,
      },
    },
  },
});
console.log(user.profile.name);

You can also use Prisma's $extends feature to create custom extensions that simplify access to your nested fields, allowing you to define getter methods to access fields directly without navigating through scalars:

const prisma = new PrismaClient().$extends({
  result: {
    user: {
      profile: {
        needs: { profile: true },
        compute(user) {
          return user.profile.scalars;
        },
      },
    },
  },
});

The latest option i would suggest would be to downgrade to v4.15.0 if none of the options above work

mint quail
#

ty !

just checked and the composites disapeared on v5