prisma-client-rust
prisma-client-rust copied to clipboard
`and` operator with same row does not work
Problem
I have data like this in Test table
And there is code to find data which contains "abc" and "def".
let res = client
.test()
.find_many(vec![and(vec![
test::title::contains("abc".to_string()),
test::title::contains("def".to_string()),
])])
.exec()
.await
.unwrap();
dbg!(&res);
I assumed that this code shows
&res = [
Data {
id: 2,
title: "abcdefgh",
},
]
But actual output was below.
&res = [
Data {
id: 1,
title: "defgh",
},
Data {
id: 2,
title: "abcdefgh",
},
]
It seems like only last condition in and is applied. Also, this works as expected if whereparams are for different rows
Version
- rust 1.71.0
- prisma-client-rust 0.6.10
Hmm, I suspect that the second contains is overwriting the first one. What you're trying to do may not actually be possible at the moment, I think the proper implementation of and would be something like this:
client
.test()
.find_many(vec![and![
vec![test::title::contains("abc".to_string())]
vec![test::title::contains("def".to_string())],
]])
Also note that I used and! which lets you combine the and and vec!.