Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unique array error #417

Closed
YandiBanyuKarimaWaly opened this issue Dec 3, 2023 · 2 comments
Closed

Unique array error #417

YandiBanyuKarimaWaly opened this issue Dec 3, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@YandiBanyuKarimaWaly
Copy link

YandiBanyuKarimaWaly commented Dec 3, 2023

I come from Javascript background so apologize in advance if I don't use the correct term/syntax. I am making a tree data structure using materialized path. Each path in a database should be a unique array. However, when I generate the client it created an invalid client.

Here is an example model:

model item {
    numeric_id BigInt   @unique @default(autoincrement())
    path       BigInt[] @unique
}

Here is the offending snippet in the generated client:

impl From<UniqueWhereParam> for WhereParam {
    fn from(value: UniqueWhereParam) -> Self {
        match value {
            UniqueWhereParam::NumericIdEquals(value) => {
                Self::NumericId(_prisma::read_filters::BigIntFilter::Equals(value))
            }
            UniqueWhereParam::PathEquals(value) => {
                Self::Path(_prisma::read_filters::BigIntListFilter::Equals(value))
            }
        }
    }
}

The problem is that value on PathEquals is i64 and the expected type for BigIntListFilter::Equals is Vec<i64>.

EDIT : Forgot to mention, my current workaround is manually editing the enum. I haven't tested it but it compiles just fine.

Before:

pub enum UniqueWhereParam {
    NumericIdEquals(i64),
    PathEquals(i64),
}

After:

pub enum UniqueWhereParam {
    NumericIdEquals(i64),
    PathEquals(Vec<i64>),
}
@Brendonovich Brendonovich added the bug Something isn't working label Dec 4, 2023
@RubberDuckShobe
Copy link

Facing the same issue, this is the only thing preventing me from using this.

The model:

model Song {
    id Int @id @default(autoincrement())

    scores Score[]
    shouts Shout[]

    title             String
    artist            String
    tags              String[] @default([])
    mbid              String?
    musicbrainzTitle  String?
    musicbrainzArtist String?
    musicbrainzLength Int?
    mistagLock        Boolean  @default(false)
    coverUrl          String?
    smallCoverUrl     String?

    @@unique([title, artist, tags])
}

The error:

mismatched types
expected struct `std::string::String`
   found struct `std::vec::Vec<std::string::String>`

Generated client:

Self::TitleArtistTagsEquals(title, artist, tags) => (
    "title_artist_tags",
    ::prisma_client_rust::SerializedWhereValue::Object(vec![
        (
            title::NAME.to_string(),
            ::prisma_client_rust::PrismaValue::String(title),
        ),
        (
            artist::NAME.to_string(),
            ::prisma_client_rust::PrismaValue::String(artist),
        ),
        (
            tags::NAME.to_string(),
            ::prisma_client_rust::PrismaValue::String(tags),
        ),
    ]),
),

@Brendonovich Brendonovich linked a pull request Dec 28, 2023 that will close this issue
@Brendonovich Brendonovich removed a link to a pull request Dec 28, 2023
@Brendonovich
Copy link
Owner

Fixed in 33e5ae1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants