Extends result relations

Hi, I have 3 different objects:
model User {
id String @id @default(uuid())
auth_id String @unique
firstname String
lastname String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
sessions Session[]
challenges Challenge[]
exoskeletons ExoskeletonAttribution[]
}

model Exoskeleton {
id String @id @default(uuid())
serial String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
sessions Session[]
attributions ExoskeletonAttribution[]
}

model ExoskeletonAttribution {
id String @id @default(uuid())
exoskeletonId String
userId String
createdAt DateTime @default(now())
revokedAt DateTime?
exoskeleton Exoskeleton @relation(fields: [exoskeletonId], references: [id])
user User @relation(fields: [userId], references: [id])
}
model User {
id String @id @default(uuid())
auth_id String @unique
firstname String
lastname String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
sessions Session[]
challenges Challenge[]
exoskeletons ExoskeletonAttribution[]
}

model Exoskeleton {
id String @id @default(uuid())
serial String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
sessions Session[]
attributions ExoskeletonAttribution[]
}

model ExoskeletonAttribution {
id String @id @default(uuid())
exoskeletonId String
userId String
createdAt DateTime @default(now())
revokedAt DateTime?
exoskeleton Exoskeleton @relation(fields: [exoskeletonId], references: [id])
user User @relation(fields: [userId], references: [id])
}
The last one have a manyToOne relation for both User & Exoskeleton. My goal is to add a custom field to User, named currentExoskeleton, based on the relation to exoskeletonAttribution (i take the last in date), to fetch to associated Exoskeleton. So i started to wrote this:
result: {
user: {
currentExoskeleton: {
needs: {
exoskeletonAttribution: true,
},
compute(user) {
// nothing here for the moment
}
},
},
},
result: {
user: {
currentExoskeleton: {
needs: {
exoskeletonAttribution: true,
},
compute(user) {
// nothing here for the moment
}
},
},
},
But typescript already crying on me on the needs part, "impossible to align type boolean to never". And i would also like to know if it's possible to user async/await on compute ? (if yes, how ? should i return an async function from the compute function ?) Thanks 😉
1 Reply
DollarNavalex
DollarNavalex2mo ago
My goal would be to have access to an Exoskeleton object on the User object, based on a query from the ExoskeletonAttribution