Rémi
09/26/2022, 9:16 AMSELECT a.id, a.title
FROM a
INNER JOIN ON a.nextSession = b.id
INNER JOIN ON b.id = c.tutelageSession
INNER JOIN ON c.user = d.id
WHERE d.name NOT 'VALUE';
Here my tables :
| a (TutelageClass) | b (TutelageSession) | c | d (User) |
| ------------------- | ----------------------- | ----------------------- | --------- |
| id | id | #user | id |
| title | title | #tutelageSession | name |
| #nextSession |
My Prisma schema is the following (simplified) :
datasource db {
provider = "mongodb"
url = env("DATABASE_URL")
}
model TutelageClass {
id String @id @default(auto()) @map("_id") @db.ObjectId
title String
nextSessionId String? @db.ObjectId
nextSession TutelageSession?
}
model TutelageSession {
id String @id @default(auto()) @map("_id") @db.ObjectId
registeredStudentsIDs String[] @db.ObjectId
tutelageClassId String @unique @db.ObjectId
tutelageClass TutelageClass @relation(fields: [tutelageClassId], references: [id], onUpdate: Cascade, onDelete: Restrict)
registeredStudents User[] @relation("RegisteredStudentsToTutelageSession", fields: [registeredStudentsIDs], references: [id])
}
model User {
id String @id @default(auto()) @map("_id") @db.ObjectId
name String?
registeredToTutelageSessionIDs String[] @db.ObjectId
registeredToTutelageSession TutelageSession[] @relation("RegisteredStudentsToTutelageSession", fields: [registeredToTutelageSessionIDs], references: [id])
}
And finally, the code I'm trying :
const c = await client.tutelageClass.findMany({
select: {
id: true,
title: true,
}, where: {
nextSession: {
registeredStudents: {
none: {
id: userIdNotRegistered
}
}
}
}
});
Vladi Stevanovic
Vladi Stevanovic
Nurul
09/27/2022, 11:26 AMRémi
09/28/2022, 2:15 PMRémi
09/28/2022, 2:20 PMmodel TutelageSession {
id String @id @default(auto()) @map("_id") @db.ObjectId
title String
location String
startAt DateTime
endAt DateTime
placeLimit Int @default(20)
registeredStudentsIDs String[] @db.ObjectId
tutorsIDs String[] @db.ObjectId
tutelageClassId String @unique @db.ObjectId
tutelageClass TutelageClass @relation(fields: [tutelageClassId], references: [id], onUpdate: Cascade, onDelete: Restrict)
registeredStudents User[] @relation("RegisteredStudentsToTutelageSession", fields: [registeredStudentsIDs], references: [id])
tutors User[] @relation("TutorsToTutelageSession", fields: [tutorsIDs], references: [id])
}
Nurul
09/30/2022, 12:09 PMVladi Stevanovic
Nurul
10/04/2022, 11:39 AMon how the records are createdSo essentially the create query of these models.
Rémi
10/04/2022, 8:57 PMconst data: Omit<TutelageSession>, "id"> = ...
const session = await client.tutelageSession.create({
data
});
And the TutelageClass is for the moment manually inserted (in order to test)Nurul
10/12/2022, 4:54 PM