Required relation field not showing in generated DTO, and marked as optional in generated Entity
paultannenbaum opened this issue · comments
Paul Tannenbaum commented
I am probably doing something wrong on my end, but seems like my generated files are not correct on a 1 to many relation. I am expecting both the entity and the DTO to include the event
property on a CreateListing
object.
Prisma Schema:
generator nestjsDto {
provider = "prisma-generator-nestjs-dto"
output = "./schema"
outputToNestJsResourceStructure = "true"
entitySuffix = "Entity"
}
model Event {
...props
// Relations
listings Listing[]
}
model Listing {
...props
// Relations
event Event @relation(fields: [eventId], references: [id])
eventId Int
}
Generated Listing DTO (No event
field):
export class CreateListingDto {
legacyFeedListingId?: number;
legacySellerListingId?: number;
@ApiProperty({ enum: ListingSource })
listingSource: ListingSource;
tevoId?: number;
wholesalePrice: number;
retailPrice: number;
@ApiProperty({ enum: AccessType })
accessType: AccessType;
notes?: string;
ticketGroupSizes: number[];
vipPassNotes?: string;
parkingNotes?: string;
seatingNotes?: string;
cateringNotes?: string;
}
Generated Listing Entity (Marked as optional):
import { ListingSource, AccessType } from '@prisma/client';
import { AssetEntity } from '../../asset/entities/asset.entity';
import { EventEntity } from '../../event/entities/event.entity';
export class ListingEntity {
id: number;
legacyFeedListingId: number | null;
legacySellerListingId: number | null;
listingSource: ListingSource;
tevoId: number | null;
wholesalePrice: number;
retailPrice: number;
accessType: AccessType;
notes: string | null;
ticketGroupSizes: number[];
numberParkingInc: number;
concierge: boolean;
foodInc: boolean;
alcoholInc: boolean;
nonAlcoholInc: boolean;
vipPassInc: boolean;
vipPassNotes: string | null;
parkingNotes: string | null;
seatingNotes: string | null;
cateringNotes: string | null;
promote: boolean;
asset?: AssetEntity | null;
assetId: number | null;
event?: EventEntity;
eventId: number;
}
Benjamin Kroeger commented
relations are filtered out on CreateDTO
s by default.
You can annotate the field with @DtoRelationCanCreateOnCreate
or @DtoRelationCanConnectOnCreate
if you want to keep the field in the CreateDTO
Benjamin Kroeger commented
also, this is explained in the Readme