Hi,
First of all thank you for this complete project.
I'm currently having a problem using one-to-one relationships with Prisma.
It's probably due to a misunderstanding of the code on my part but I've been blocking for a while now.
I'm trying to create a relationship between an entity called Project with another called ProjectDrive.
This is the .prisma file entities declaration :
model Project {
id Int @id @default(autoincrement())
uuid String @unique @db.VarChar(1000)
publicName String @db.VarChar(255)
privateName String @db.VarChar(255)
slug String @db.VarChar(255)
description String @db.VarChar(500)
projectDrive ProjectDrive?
createdAt DateTime? @default(now()) @db.Timestamptz(3)
createdBy String? @db.VarChar(255)
updatedAt DateTime? @default(now()) @updatedAt @db.Timestamptz(3)
updatedBy String? @db.VarChar(255)
deletedAt DateTime? @db.Timestamptz(3)
deletedBy String? @db.VarChar(255)
}
model ProjectDrive {
id Int @id @default(autoincrement())
uuid String @unique @db.VarChar(1000)
folderId String? @unique @db.VarChar(500)
name String? @unique @db.VarChar(500)
url String? @db.VarChar(500)
project Project? @relation(fields: [puid], references: [uuid])
puid String? @unique
createdAt DateTime? @default(now()) @db.Timestamptz(3)
createdBy String? @db.VarChar(255)
updatedAt DateTime? @default(now()) @updatedAt @db.Timestamptz(3)
updatedBy String? @db.VarChar(255)
deletedAt DateTime? @db.Timestamptz(3)
deletedBy String? @db.VarChar(255)
}
After migrate and generate I got this error :
Type 'ProjectDriveModel' is not assignable to type '(Without<ProjectDriveCreateInput, ProjectDriveUncheckedCreateInput> & ProjectDriveUncheckedCreateInput) | (Without<...> & ProjectDriveCreateInput)'.
Type 'ProjectDriveModel' is not assignable to type 'Without<ProjectDriveUncheckedCreateInput, ProjectDriveCreateInput> & ProjectDriveCreateInput'.
Type 'ProjectDriveModel' is not assignable to type 'Without<ProjectDriveUncheckedCreateInput, ProjectDriveCreateInput>'.
Types of property 'id' are incompatible.
Type 'number' is not assignable to type 'undefined'.
I understand why it failed in the code :
ProjectDriveModel generated by prisma :
export declare class ProjectDriveModel implements ProjectDrive {
id: number;
uuid: string;
folderId: string | null;
name: string | null;
url: string | null;
project: ProjectModel | null;
puid: string | null;
createdAt: Date | null;
createdBy: string | null;
updatedAt: Date | null;
updatedBy: string | null;
deletedAt: Date | null;
deletedBy: string | null;
}
ProjectDriveCreateInput :
export type ProjectDriveCreateInput = {
uuid: string
folderId?: string | null
name?: string | null
url?: string | null
project?: ProjectCreateNestedOneWithoutProjectDriveInput
createdAt?: Date | string | null
createdBy?: string | null
updatedAt?: Date | string | null
updatedBy?: string | null
deletedAt?: Date | string | null
deletedBy?: string | null
}
ProjectDriveUncheckedCreateInput :
export type ProjectDriveUncheckedCreateInput = {
id?: number
uuid: string
folderId?: string | null
name?: string | null
url?: string | null
puid?: string | null
createdAt?: Date | string | null
createdBy?: string | null
updatedAt?: Date | string | null
updatedBy?: string | null
deletedAt?: Date | string | null
deletedBy?: string | null
}
It seems that ProjectDriveModel is in conflict with ProjectDriveUncheckedCreateInput on the id field, but I checked if I remove the relation those files are the same, and I got no errors.
I'm really out of ideas, if you can help me ๐๐ผ
Tell me if it's not clear or if you need more explanations !
Thank you !