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

Allow arrays in unique where params #421

Merged
merged 1 commit into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading