I have these two tables in Prisma schema:
model Accounts {
id Int @id @default(autoincrement())
name String @db.VarChar(100)
description String? @db.VarChar(255)
timeZone Int @default(0)
tableBusinessApplication AccountsBusinessApplications[]
}
model AccountsBusinessApplications {
id Int @id @default(autoincrement())
account Accounts @relation(fields: [accountId], references: [id])
accountId Int
name String @db.VarChar(100)
identification String @db.VarChar(100)
secretKey String @db.VarChar(32)
}
I have the follow piece of code:
const name = 'Accounts'
prisma[name].findFirst({
where: { id: 1}
}).then(result => { console.log(result) })
and as a result I have:
{
id: 1,
name: 'test',
description: 'test description',
timeZone: 0
}
but I don't see 'tableBusinessApplication' inside. How can I get all data if I know only first class name "Accounts" and I can't use 'Include' in Query?
I try to find how to get a list of fields using prisma class, but it seems like there is nothing.
As of Prisma 4:
import { Prisma } from '@prisma/client';
console.log("Account fields:", Prisma.dmmf.datamodel.models.find(model => model.name === "Account").fields)
As of Prisma 5:
const allowedFields = Object.keys(prisma[this.modelName].fields)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With