Repository: Brendonovich/prisma-client-rust (language: rust)

Issue:
Enum list can't call to_string on Vec
using arrays of enum in the schema causes a vec to be generated

```
model RebelCollect {
    id             Int          @id @default(autoincrement())
    hero_ids       HeroId[]
}
```

```
pub struct Data {
        #[serde(rename = "id")]
        pub id: i32,
        #[serde(rename = "hero_ids")]
        pub hero_ids: Vec<super::HeroId>,
}
```

then in the `WhereInput` serialization it tries to call `to_string` on a `Vec<HeroId>`

```
      Self::RebelsConfigIdHeroIdsEquals(rebels_config_id, hero_ids) => (
                    "rebelsConfigId_hero_ids",
                    ::prisma_client_rust::SerializedWhereValue::Object(vec![
                        (
                            rebels_config_id::NAME.to_string(),
                            ::prisma_client_rust::PrismaValue::Int(rebels_config_id as i64),
                        ),
                        (
                            hero_ids::NAME.to_string(),
                            ::prisma_client_rust::PrismaValue::Enum(hero_ids.to_string()), // this line
                        ),
                    ]),
                ),
```

```
`std::vec::Vec<prisma::HeroId>` cannot be formatted with the default formatter


400   | pub struct Vec<T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global> {
      | ------------------------------------------------------------------------------------------------
      | |
      | doesn't satisfy `std::vec::Vec<prisma::HeroId>: ToString`
      | doesn't satisfy `std::vec::Vec<prisma::HeroId>: std::fmt::Display`
      |
      = note: the following trait bounds were not satisfied:
              `std::vec::Vec<prisma::HeroId>: std::fmt::Display`
              which is required by `std::vec::Vec<prisma::HeroId>: ToString`
              `[prisma::HeroId]: std::fmt::Display`
              which is required by `[prisma::HeroId]: ToString`

```


Discussion / hints:
Classic enum mistake, my bad.

Fix patch:
diff --git a/sdk/src/args.rs b/sdk/src/args.rs
index 9df86bd4..8763b074 100644
--- a/sdk/src/args.rs
+++ b/sdk/src/args.rs
@@ -108,10 +108,11 @@ impl GenerateArgs {
 
                     let mut name = e.name.clone();
 
-                    if p.name.contains("ListFilter") {
+                    // checking for both is invalid - fields can be list or null but not both
+                    // TODO: make this more typesafe to correspond with fields
+                    if p.name.contains("List") {
                         name += "List";
-                    }
-                    if p.name.contains("Nullable") {
+                    } else if p.name.contains("Nullable") {
                         name += "Nullable";
                     }
 
@@ -305,34 +306,24 @@ impl GenerateArgs {
     }
 
     pub fn read_filter(&self, field: &ScalarField) -> Option<&Filter> {
-        match &field.field_type {
-            FieldType::Scalar(typ, _) => {
-                let mut typ = match typ.to_string().as_str() {
-                    "Boolean" => "Bool".to_string(),
-                    n => n.to_string(),
-                };
-
-                match field.arity {
-                    FieldArity::List => typ += "List",
-                    FieldArity::Optional => typ += "Nullable",
-                    _ => {}
-                }
-
-                self.read_filters.iter().find(|f| f.name == typ)
-            }
-            FieldType::Enum(e) => {
-                let mut typ = e.clone();
+        let postfix = match field.arity {
+            FieldArity::List => "List",
+            FieldArity::Optional => "Nullable",
+            _ => "",
+        };
 
-                match field.arity {
-                    FieldArity::List => typ += "List",
-                    FieldArity::Optional => typ += "Nullable",
-                    _ => {}
-                }
+        let base = match &field.field_type {
+            FieldType::Scalar(typ, _) => match typ.to_string().as_str() {
+                "Boolean" => "Bool".to_string(),
+                n => n.to_string(),
+            },
+            FieldType::Enum(e) => e.clone(),
+            _ => return None,
+        };
 
-                self.read_filters.iter().find(|f| &f.name == e)
-            }
-            _ => None,
-        }
+        self.read_filters
+            .iter()
+            .find(|f| f.name == format!("{base}{postfix}"))
     }
 
     pub fn write_filter(&self, field: &ScalarField) -> Option<&Filter> {


Test patch:
diff --git a/tests/database/postgres/prisma/schema.prisma b/tests/database/postgres/prisma/schema.prisma
index a63e9dde..44aa4038 100644
--- a/tests/database/postgres/prisma/schema.prisma
+++ b/tests/database/postgres/prisma/schema.prisma
@@ -11,10 +11,12 @@ generator client {
 }
 
 model SomeModel {
-    id                 String    @id
+    id                 String     @id
     some_column        Json?
     some_enum          SomeEnum
     some_enum_optional SomeEnum?
+    // https://github.com/Brendonovich/prisma-client-rust/issues/303
+    enum_list          SomeEnum[]
 }
 
 enum SomeEnum {