Fervore
Explore posts from serversPPrisma
•Created by Fervore on 7/22/2024 in #help-and-questions
Nested relation query help
hello @moosthuizen, thanks for reaching out, here are the models in question from the schema.prisma
model Member {
id String @id() @default(cuid())
name String
email String?
phone Int?
sex String
DNI String
memberships Membership[]
payments Payment[]
orgId String
organization Organization @relation(fields: [orgId], references: [id])
}
model Membership {
id String @id() @default(cuid())
period Int
cost Int
name String
members Member[]
payments Payment[]
authorId String
createdBy User @relation(fields: [authorId], references: [id])
orgId String
organization Organization @relation(fields: [orgId], references: [id])
}
model Payment {
id String @id() @default(cuid())
startDate DateTime @default(now())
endDate DateTime
membership Membership @relation(fields: [membershipId], references: [id])
membershipId String
amount Int @default(0)
member Member @relation(fields: [memberId], references: [id])
memberId String
createdBy User @relation(fields: [authorId], references: [id])
authorId String
createdAt DateTime @default(now())
}
model Organization {
id String @id() @default(cuid())
name String
createdAt DateTime @default(now())
slug String
members Member[]
users User[] @relation("organization")
ownerId String @unique()
owner User @relation("owns", fields: [ownerId], references: [id])
memberships Membership[]
}
model Member {
id String @id() @default(cuid())
name String
email String?
phone Int?
sex String
DNI String
memberships Membership[]
payments Payment[]
orgId String
organization Organization @relation(fields: [orgId], references: [id])
}
model Membership {
id String @id() @default(cuid())
period Int
cost Int
name String
members Member[]
payments Payment[]
authorId String
createdBy User @relation(fields: [authorId], references: [id])
orgId String
organization Organization @relation(fields: [orgId], references: [id])
}
model Payment {
id String @id() @default(cuid())
startDate DateTime @default(now())
endDate DateTime
membership Membership @relation(fields: [membershipId], references: [id])
membershipId String
amount Int @default(0)
member Member @relation(fields: [memberId], references: [id])
memberId String
createdBy User @relation(fields: [authorId], references: [id])
authorId String
createdAt DateTime @default(now())
}
model Organization {
id String @id() @default(cuid())
name String
createdAt DateTime @default(now())
slug String
members Member[]
users User[] @relation("organization")
ownerId String @unique()
owner User @relation("owns", fields: [ownerId], references: [id])
memberships Membership[]
}
6 replies