You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For backwards compatibility, I would like the Type creation JSON input to look like this:
{
"DESCRIPTION": "string",
"TYPEGROUP_ID": 1
}
However, this format is incompatible with the generated Prisma.TypeCreateInput object because TypeGroup requires the inclusion of an object with create, connectOrCreate, or connect options.
When I add the @DtoRelationCanConnectOnCreate annotation to the TypeGroup reference within the Type model, I then need to provide the following JSON structure:
This is more verbose than desired and is incompatible with the existing front-end structure.
Is there a way to configure the decorators in the Prisma schema so my desired JSON format is outputted, whilst passing the correct object format to Prisma (including the connect property) automatically?
I'm currently transforming the DTO object manually before passing it to the service.
Any help is much appreciated
The text was updated successfully, but these errors were encountered:
Staijn1
changed the title
How to use @DtoRelationIncludeId for creating object with reference connect?
How to use @DtoRelationIncludeId for creating an object with reference connect?
Oct 27, 2024
All relation fields (including their id fields) are omitted by default and need to be made explicitly visible by respective annotations. When I forked this generator, only annotations like @DtoRelationCanConnectOnCreate where available that was, however, in most cases too verbose for me, like in your case. I also just wanted to pass the id. That's why I introduced the @DtoRelationIncludeId annotation. However, it does not automatically map it to Prisma.TypeCreateInput (i.e., { connect: { id: body.TYPEGROUP_ID } }).
Your Prisma schema is already correct. It should generate something like this:
At least that's how we use it in our projects. So, you can't just pass the Dto directly, but need to handle it respectively in your backend service. But it's cleaner for the frontend.
Hello,
I'm currently re-writing an existing API and need to maintain backwards compatibility for my DTOs to minimize front-end changes.
In my database schema, I have two models:
Type
andTypeGroup
. TheType
model references a parentTypeGroup
as shown in my Prisma schema:For backwards compatibility, I would like the Type creation JSON input to look like this:
However, this format is incompatible with the generated Prisma.TypeCreateInput object because TypeGroup requires the inclusion of an object with create, connectOrCreate, or connect options.
When I add the @DtoRelationCanConnectOnCreate annotation to the TypeGroup reference within the Type model, I then need to provide the following JSON structure:
This is more verbose than desired and is incompatible with the existing front-end structure.
Is there a way to configure the decorators in the Prisma schema so my desired JSON format is outputted, whilst passing the correct object format to Prisma (including the
connect
property) automatically?I'm currently transforming the DTO object manually before passing it to the service.
Any help is much appreciated
The text was updated successfully, but these errors were encountered: