繁体   English   中英

Prisma NodeJS:在查询中包含 ID

[英]Prisma NodeJS: Include ID in query

Model:

model Foo {
    id Int @id @default(autoincrement())
    name String
    bar Bar?
}

model Bar {
    id Int @id @default(autoincrement())
    name String
    foo Foo @relation(fields: [fooId], references: [id])
    fooId Int
}

节点代码:

import { PrismaClient } from "@prisma/client";

async function main() {
   let client = new PrismaClient();
   let foo = client.foo.findFirst( ??? )
};

main()

里面有什么??? 获得包含FooBar的 ID 的 object(以及 model 变大后的所有其他字段)?

请注意,如果可能,它不应使用select ,因为在更大的 model 中,我需要列出每个字段,包括我不想做的id 如果除了原始 SQL 之外没有其他选择,请告诉我。

截至文档

const result = await prisma.user.findUnique({
  where: {
    id: 42,
  },
})

所以,在你的情况下:

client.foo.findFirst( ??? )

会成为:

client.foo.findFirst({
     where: {
          id: yourvaluehere
     }
})

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM