Brendonovich / prisma-client-rust

Type-safe database access for Rust
https://prisma.brendonovich.dev
Apache License 2.0
1.75k stars 106 forks source link

`and` operator with same row does not work #394

Open nazo6 opened 10 months ago

nazo6 commented 10 months ago

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

Brendonovich commented 10 months ago

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