Hey there, i'm having some trouble when I extend a Prisma client type (in typescript). I have a User, which have a oneToOne relation with a Preferences model, looking like that:
model User { id String @id @default(uuid()) auth_id String @unique firstname String lastname String data Json activationToken String? @default(uuid()) createdAt DateTime @default(now()) updatedAt DateTime @updatedAt following User[] @relation("Follow") followers User[] @relation("Follow") exoskeletons ExoskeletonAttribution[] challenges Challenge[] authoredChallenges Challenge[] @relation(name: "challengeAuthor") surveys Survey[] preferences Preferences?}model Preferences { id String @id @default(uuid()) userId String @unique user User @relation(fields: [userId], references: [id]) weekStart WeekStartDay @default(MONDAY) darkMode Boolean @default(false) unitType UnitType @default(METRIC) createdAt DateTime @default(now()) updatedAt DateTime @updatedAt}
model User { id String @id @default(uuid()) auth_id String @unique firstname String lastname String data Json activationToken String? @default(uuid()) createdAt DateTime @default(now()) updatedAt DateTime @updatedAt following User[] @relation("Follow") followers User[] @relation("Follow") exoskeletons ExoskeletonAttribution[] challenges Challenge[] authoredChallenges Challenge[] @relation(name: "challengeAuthor") surveys Survey[] preferences Preferences?}model Preferences { id String @id @default(uuid()) userId String @unique user User @relation(fields: [userId], references: [id]) weekStart WeekStartDay @default(MONDAY) darkMode Boolean @default(false) unitType UnitType @default(METRIC) createdAt DateTime @default(now()) updatedAt DateTime @updatedAt}
I made this interface:
import { Preferences, User } from "@prisma/client"export interface UserWithRoles extends User { roles: string[]}
import { Preferences, User } from "@prisma/client"export interface UserWithRoles extends User { roles: string[]}
And I have a function that find a user, aggregate it in a new object with roles array, and the output of this function seems to drop the preferences relation, even if I explicitly include it in my findUnique function. Not an expert in typescript yet, so I may miss something basic, but it should works from what I understand.
Need a lil help on that one please, Thanks !
Solution
And adding them manually would have force me to explicitly define all Preferences properties too, since the prisma findUnique function doesn't return a Preferences object, but a custom object based on my query (from what I understand), so the object is not Exactly like the Preferences object would be.