How to extend User Prisma model with Custom 1to1 relations when used @better-auth/cli

Hi there. Could you help please with subject? How I can add custom additional field as 1 to 1 relation?
model User {
id String @id
firstName String @map("name")
email String
emailVerified Boolean
image String?
createdAt DateTime
updatedAt DateTime
role String?
banned Boolean?
banReason String?
banExpires DateTime?
isAnonymous Boolean?
lastName String
sessions Session[]
accounts Account[]
members Member[]
invitations Invitation[]
apikeys Apikey[]

/// how to infer and provide custom 1 to 1 model relation via additional fields?
profile Profile?

@@unique([email])
@@map("user")
@@schema("nextjs-backend")
}

model Profile {
/// @zod.uuid()
id String @id @default(uuid()) @db.Uuid
dob DateTime? @db.Date
bio String?
gender GENDER?
avatarUrl String?

phones String[]
languages String[]
/// @zod.uuid()
userId String? @unique @map("user_id") @db.Uuid
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)

addressId String? @unique @map("address_id") @db.Uuid
address ProfileAddress? @relation(fields: [addressId], references: [id], onDelete: Cascade)

education ProfileEducation[]
experience ProfileExperience[]

@@unique([userId, addressId])
@@index(fields: [userId])
@@index(fields: [addressId])
@@map("profile")
@@schema("nextjs-backend")
}
model User {
id String @id
firstName String @map("name")
email String
emailVerified Boolean
image String?
createdAt DateTime
updatedAt DateTime
role String?
banned Boolean?
banReason String?
banExpires DateTime?
isAnonymous Boolean?
lastName String
sessions Session[]
accounts Account[]
members Member[]
invitations Invitation[]
apikeys Apikey[]

/// how to infer and provide custom 1 to 1 model relation via additional fields?
profile Profile?

@@unique([email])
@@map("user")
@@schema("nextjs-backend")
}

model Profile {
/// @zod.uuid()
id String @id @default(uuid()) @db.Uuid
dob DateTime? @db.Date
bio String?
gender GENDER?
avatarUrl String?

phones String[]
languages String[]
/// @zod.uuid()
userId String? @unique @map("user_id") @db.Uuid
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)

addressId String? @unique @map("address_id") @db.Uuid
address ProfileAddress? @relation(fields: [addressId], references: [id], onDelete: Cascade)

education ProfileEducation[]
experience ProfileExperience[]

@@unique([userId, addressId])
@@index(fields: [userId])
@@index(fields: [addressId])
@@map("profile")
@@schema("nextjs-backend")
}
Thank you very much!
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?