我有两张桌子:
model Collection {
id String @id @default(uuid()) @db.Uuid/
floorPrices CollectionFloorPrice[]
}
model CollectionFloorPrice {
id String @id @default(uuid()) @db.Uuid
collection Collection @relation(fields: [collectionId], references: [id])
collectionId String @db.Uuid
}如何查询仅显示在CollectionFloorPrice中的行的集合?在SQL中,这将是一个简单的联接。
这不管用:
return await this.prisma.collection.findMany({
where: {
floorPrices: {
exists: true,
},
},
});发布于 2022-03-17 04:54:01
Prisma对一个名为CollectionFloorPrice的模型的关系过滤器如下:
export type CollectionFloorPriceFilter = {
every?: CollectionFloorPriceWhereInput | null
some?: CollectionFloorPriceWhereInput | null
none?: CollectionFloorPriceWhereInput | null
}要只获得至少有一个Collection的CollectionFloorPrice,您应该使用some (而不是exists),并指定一个条件,该条件总是对存在的任何相关记录返回true。
如果希望查询包括相关的CollectionFloorPrice,则必须在include属性中指定它。
return await this.prisma.collection.findMany({
where: {
floorPrices: {
some: {
id: { not: "" } // It always should be true.
},
},
},
// if you want to include related floor prices in returned object:
include: {
floorPrices: true,
},
});发布于 2022-10-19 09:08:13
prisma.collection.findMany({
where: { floorPrices: { some: {} } }
})https://stackoverflow.com/questions/71500284
复制相似问题