Skip to content

Commit

Permalink
Merge pull request #421 from Brendonovich/417-unique-array-error
Browse files Browse the repository at this point in the history
Allow arrays in unique where params
  • Loading branch information
Brendonovich authored Dec 28, 2023
2 parents ad328c5 + 33e5ae1 commit 3ed87d4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
8 changes: 4 additions & 4 deletions cli/src/generator/models/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,18 +174,18 @@ pub fn module(
let filter_enum = format_ident!("{}Filter", &read_filter.name);

// Add equals query functions. Unique/Where enum variants are added in unique/primary key sections earlier on.
let equals = match (model.field_is_primary(field_name), model.field_is_unique(field_name), field.arity.is_required()) {
(true, _, _) | (_, true, true) => quote! {
let equals = match (model.field_is_primary(field_name), model.field_is_unique(field_name), field.arity.is_optional()) {
(true, _, _) | (_, true, false) => quote! {
pub fn equals<T: From<UniqueWhereParam>>(value: #field_type) -> T {
UniqueWhereParam::#equals_variant(value).into()
}
},
(_, true, false) => quote! {
(_, true, true) => quote! {
pub fn equals<A, T: #pcr::FromOptionalUniqueArg<Set, Arg = A>>(value: A) -> T {
T::from_arg(value)
}
},
(_, _, _) => quote! {
(false, false, _) => quote! {
pub fn equals(value: #field_type) -> WhereParam {
WhereParam::#field_name_pascal(_prisma::read_filters::#filter_enum::Equals(value))
}
Expand Down
8 changes: 7 additions & 1 deletion cli/src/generator/models/where_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ impl Variant {
field_name: field.name().to_string(),
field_required_type: field
.field_type()
.to_tokens(module_path, &dml::FieldArity::Required)
.to_tokens(
module_path,
&match field.arity() {
dml::FieldArity::Optional => dml::FieldArity::Required,
a => *a,
},
)
.unwrap(),
read_filter_name: read_filter.name.to_string(),
optional: matches!(field.arity(), dml::FieldArity::Optional),
Expand Down

0 comments on commit 3ed87d4

Please sign in to comment.