I have two models in Prisma: User
i UserInfo
. I am also using class-validator
and class-transformer
if it matters.
model User {
userId Int @id @default(autoincrement())
email String @unique
userInfo UserInfo @relation(references: [userInfoId], fields: [userInfoId], onDelete: Cascade)
userInfoId Int
}
model PersonalInfo {
personalInfoId Int @id @default(autoincrement())
firstName String
User User[]
}
They are in a one-to-one relationship, i.e. one user can be associated with one userInfo. How can this connection be mapped in DTO? The only thing that comes to my mind is to add a field of a given type:
export class CreateUserDto {
@ApiProperty()
@IsEmail()
@IsString()
@IsNotEmpty()
email: string;
@IsNotEmpty()
userInfo: UserInfo;
}
Is it the correct solution? Or is there another, elegant way?