Prisma:findMany 与 where 的关系不起作用
Prisma: relationship in findMany with where doesn't work
我正在尝试在 this documentation 之后使用 Prisma 进行查询,但接受的对象没有 where 作为属性。
我的代码:
return await prisma.post_engagement.findMany({
select: {
user: {
where: {
enabled: true,
deleted_at: null,
}
}
}
});
编译错误:
index.ts:15:17 - error TS2322: Type '{ where: { enabled: true; deleted_at: null; }; }' is not assignable to type 'boolean | userArgs'.
Object literal may only specify known properties, and 'where' does not exist in type 'userArgs'.
15 where: {
~~~~~~~~
16 enabled: true,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
17 deleted_at: null,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 }
~~~~~~~~~~~~~~~~~
node_modules/.prisma/client/index.d.ts:68498:5
68498 user?: boolean | userArgs
~~~~
The expected type comes from property 'user' which is declared here on type 'post_engagementSelect'
模式:
model user {
id Int @id @default(autoincrement()) @db.UnsignedInt
email String? @unique(map: "user_email_unique") @db.VarChar(255)
username String? @unique(map: "user_username_unique") @db.VarChar(255)
enabled Boolean? @default(true)
deleted_at DateTime? @db.Timestamp(0)
}
model post_engagement {
id Int @id @default(autoincrement()) @db.UnsignedInt
user_id Int @db.UnsignedInt
created_at DateTime @default(now()) @db.Timestamp(0)
updated_at DateTime @default(now()) @db.Timestamp(0)
user user @relation(fields: [user_id], references: [id], onUpdate: Restrict, map: "post_engagement_ibfk_2")
@@index([user_id], map: "user_id")
}
我是不是漏掉了什么?
where
参数位于查询选项的顶层,但您仍然可以使用它来指定关系条件。
await prisma.post_engagement.findMany({
select: {
user: true
},
where: {
user: {
enabled: true,
deleted_at: null
}
}
})
我正在尝试在 this documentation 之后使用 Prisma 进行查询,但接受的对象没有 where 作为属性。
我的代码:
return await prisma.post_engagement.findMany({
select: {
user: {
where: {
enabled: true,
deleted_at: null,
}
}
}
});
编译错误:
index.ts:15:17 - error TS2322: Type '{ where: { enabled: true; deleted_at: null; }; }' is not assignable to type 'boolean | userArgs'.
Object literal may only specify known properties, and 'where' does not exist in type 'userArgs'.
15 where: {
~~~~~~~~
16 enabled: true,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
17 deleted_at: null,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 }
~~~~~~~~~~~~~~~~~
node_modules/.prisma/client/index.d.ts:68498:5
68498 user?: boolean | userArgs
~~~~
The expected type comes from property 'user' which is declared here on type 'post_engagementSelect'
模式:
model user {
id Int @id @default(autoincrement()) @db.UnsignedInt
email String? @unique(map: "user_email_unique") @db.VarChar(255)
username String? @unique(map: "user_username_unique") @db.VarChar(255)
enabled Boolean? @default(true)
deleted_at DateTime? @db.Timestamp(0)
}
model post_engagement {
id Int @id @default(autoincrement()) @db.UnsignedInt
user_id Int @db.UnsignedInt
created_at DateTime @default(now()) @db.Timestamp(0)
updated_at DateTime @default(now()) @db.Timestamp(0)
user user @relation(fields: [user_id], references: [id], onUpdate: Restrict, map: "post_engagement_ibfk_2")
@@index([user_id], map: "user_id")
}
我是不是漏掉了什么?
where
参数位于查询选项的顶层,但您仍然可以使用它来指定关系条件。
await prisma.post_engagement.findMany({
select: {
user: true
},
where: {
user: {
enabled: true,
deleted_at: null
}
}
})