prisma-client-rust icon indicating copy to clipboard operation
prisma-client-rust copied to clipboard

`and` operator with same row does not work

Open nazo6 opened this issue 2 years ago • 1 comments

Problem

I have data like this in Test table image

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

nazo6 avatar Sep 01 '23 15:09 nazo6

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!.

Brendonovich avatar Sep 02 '23 04:09 Brendonovich