Topi Pihko
03/30/2022, 2:39 PMasync getFactories(enterpriseId: number): Promise<Factory[]> {
return (
await this.prisma.enterprise.findFirst({
where: {
id: enterpriseId,
},
include: {
site: {
include: {
factory: true,
},
},
},
})
).site
.map((site) => {
return site.factory;
})
.flat();
}
Austin
03/30/2022, 10:42 PMFactory
model instead, but I would need to see your schema to know for sure.Topi Pihko
03/31/2022, 11:29 AM```model Enterprise {
id Int @id @default(autoincrement()) @map("ID")
name String? @map("Name")
site Site[]
}
model Site {
id Int @id @default(autoincrement()) @map("ID")
name String? @map("Name")
enterpriseId Int @map("EnterpriseID")
enterprise Enterprise @relation(fields: [enterpriseId], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "To_Enterprise")
factory Factory[]
@@index([enterpriseId], map: "fki_To_Enterprise")
}
model Factory {
id Int @id @default(autoincrement()) @map("ID")
siteId Int @map("SiteID")
name String? @map("Name")
site Site @relation(fields: [siteId], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "To_Site")
}```
Austin
03/31/2022, 8:42 PMlet result = await prisma.factory.findMany({
where: {
site: {
enterprise: {
id: enterpriseId
}
}
}
})
Topi Pihko
04/08/2022, 12:12 PM