Created
February 7, 2024 16:40
-
-
Save 7iquid/ea40fcf4017ca00887c3fbae4df7ec83 to your computer and use it in GitHub Desktop.
prisma relation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
model Users { | |
id String @id @default(auto()) @map("_id") @db.ObjectId | |
name String | |
applicant Applicant? | |
reviewed_applicant Applicant[] @relation("ParentChild") | |
} | |
model Applicant { | |
id String @id @default(auto()) @map("_id") @db.ObjectId | |
status Boolean | |
owner Users @relation(fields: [owner_id], references: [id]) | |
owner_id String @unique @db.ObjectId | |
reviewed_by Users @relation("ParentChild", fields: [reviewed_by_id], references: [id], onDelete: Cascade, onUpdate: NoAction) | |
reviewed_by_id String @unique @db.ObjectId | |
} | |
const users = await prisma.users.findMany({ | |
include: { | |
applicant: true, | |
reviewed_applicant: true | |
}, | |
}); | |
console.log("users", users); | |
output: | |
users [ | |
{ | |
id: '65ba62500bfd1f23de36476d', | |
name: 'Intern Dela Cruz', | |
applicant: { | |
id: '65c3a8b83460a35367ff3bfd', | |
status: true, | |
owner_id: '65ba62500bfd1f23de36476d', | |
reviewed_by_id: '65c2d244816901d1ddbe8779' | |
}, | |
reviewed_applicant: [] | |
}, | |
{ | |
id: '65c2d244816901d1ddbe8779', | |
name: 'Siñior Jake Simpas', | |
applicant: null, | |
reviewed_applicant: [ { | |
id: '65ba62500bfd1f23de36476d', | |
name: 'Juan Dela Cruz', | |
} ] | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment