Skip to content
This repository has been archived by the owner on Jan 5, 2025. It is now read-only.

Missing generated relation DTO's #15

Open
paultannenbaum opened this issue Nov 3, 2021 · 4 comments
Open

Missing generated relation DTO's #15

paultannenbaum opened this issue Nov 3, 2021 · 4 comments

Comments

@paultannenbaum
Copy link

Hi @benkroeger, thanks for replying back to my issue about relations in #14 .

So I just tried your suggestion of adding in the annotated relations, but I am now running into more issues. The create-${resource}.dto.ts is being appropriately updated with the new relations, however those relation entities are not being generated themselves. Here is an example:

schema.prisma

generator nestjsDto {
  provider                        = "prisma-generator-nestjs-dto"
  output                          = "./schema"
  outputToNestJsResourceStructure = "true"
  entitySuffix                    = "Entity"
}

model Asset {
    ...otherProps
    /// @DtoRelationCanCreateOnCreate
    venue                       Venue           @relation(fields: [venueId], references: [id])
    venueId                     Int
}

create-asset.dto.ts

import { ApiExtraModels } from '@nestjs/swagger';
import { CreateVenueDto } from '../../venue/dto/create-venue.dto';

export class CreateAssetVenueRelationInputDto {
  create: CreateVenueDto;
}

@ApiExtraModels(CreateVenueDtoEntity, CreateAssetVenueRelationInputDtoEntity)
export class CreateAssetDto {
  ...otherProps
  venue: CreateAssetVenueRelationInputDtoEntity;
}

In the above example, the CreateVenueDtoEntity and CreateAssetVenueRelationInputDtoEntity called in the @ApiExtraModels decorator do not exist/have not been generated, and neither has the CreateAssetVenueRelationInputDtoEntity found in the DTO definition.

Because of this, the TS compiler is failing. Any ideas what is going wrong here?

@paultannenbaum
Copy link
Author

paultannenbaum commented Nov 15, 2021

@benkroeger any idea on if this issue is something unique to me, or an actual bug with the repo?

@benkroeger
Copy link
Member

this appears to be an issue with the entitySuffix property.
Can you (temporarily) work without specifying it?
Also, a PR fixing this is highly welcome

@piradata
Copy link

this appears to be an issue with the entitySuffix property. Can you (temporarily) work without specifying it? Also, a PR fixing this is highly welcome

Why do you think entitySuffix is causing this behaviour? Can you show the part of the code that is to blame?

Would like to open a PR fixing it because ive run into the same problem, but as i am new to the codebase I dont even know where the problem is located.

@benkroeger
Copy link
Member

because with en empty entitySuffix it works as expected :)
generateRelationInput computes the class name without the Entity suffix while the class is actually generated with a different name

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

3 participants