在我的例子中,我有一個將獎金加入賭場的模式。查詢非常適合資料,但我無法通過查詢本身進行過濾。我使用的 where 子句似乎是正確的,但我得到一個錯誤,指出物件文字可能只指定已知屬性,并且型別中不存在“nodeposit”。但我可以查詢該資料。
const data = await prisma.casino_p_casinos.findMany({
where: {
approved: 1,
rogue: 0,
bonuses: {
nodeposit: { gt : 0 },
}
},
select: {
id: true,
clean_name: true,
casino: true,
button: true,
bonuses: {
where: {
nodeposit: { gt: 0 },
},
},
},
take: 14,
});
如果我洗掉 WHERE 子句中的 bonus pard,查詢將按預期作業,但我想獲取每個賭場的所有獎金,但前提是獎金包含 nodeposit 值。
這就是我想要使用的。
const data = await prisma.casino_p_casinos.findMany({
where: {
approved: 1,
rogue: 0,
bonuses: {
nodeposit: { gt : 0 },
},
},
select: {
id: true,
clean_name: true,
casino: true,
button: true,
bonuses: true,
},
take: 14,
});
模式:
model casino_p_casinos {
id Int @id @default(autoincrement())
casino String?
type String?
url String?
bonuses casino_p_bonus[]
model casino_p_bonus {
id Int @id @default(autoincrement())
parent Int
game String?
freespins Int?
freeplay String?
nodeposit Int?
deposit Int?
casino_p_casinos casino_p_casinos @relation(fields: [parent], references: [id])
}
uj5u.com熱心網友回復:
你有一個一對多的關系,所以當你添加一個 where 子句時,你又多了一層 with some,every或者none像
const data = await prisma.casino_p_casinos.findMany({
where: {
approved: 1,
rogue: 0,
bonuses: {
// 'some' can be replaced by 'every' or 'none' here
some: {
nodeposit: { gt: 0 }
}
}
},
select: {
id: true,
clean_name: true,
casino: true,
button: true,
bonuses: true
},
take: 14
})
此查詢將過濾casinos某些nodeposit大于 0 的部分并回傳所有獎金,甚至包括那些等于 0 的獎金。
然后,如果您只想在有一些的賭場中bonuses使用nodeposit大于 0 的值,您應該這樣做:
const data = await prisma.casino_p_casinos.findMany({
where: {
approved: 1,
rogue: 0,
bonuses: {
// 'some' can be replaced by 'every' or 'none' here
some: {
nodeposit: { gt: 0 }
}
}
},
select: {
id: true,
clean_name: true,
casino: true,
button: true,
bonuses: {
where: {
nodeposit: { gt: 0 }
}
}
},
take: 14
})
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/536555.html
下一篇:在沒有主鍵的表中查找重復項
