Skip to content

Commit

Permalink
add is_null for optional single relations
Browse files Browse the repository at this point in the history
  • Loading branch information
Brendonovich committed Dec 17, 2022
1 parent 967cfb8 commit bebe1e7
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions cli/src/generator/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,9 +506,9 @@ pub fn generate(args: &GenerateArgs, module_path: TokenStream) -> Vec<TokenStrea
}
});
}

let with_fn = with_params::builder_fn(&field);

if field.arity.is_list() {
let order_by_fn = order_by::fetch_builder_fn(&relation_model_name_snake);
let pagination_fns = pagination::fetch_builder_fns(&relation_model_name_snake);
Expand Down Expand Up @@ -589,10 +589,29 @@ pub fn generate(args: &GenerateArgs, module_path: TokenStream) -> Vec<TokenStrea

// Only allow disconnect if field is not required
if field.arity.is_optional() {
let is_null_variant = format_ident!("{}IsNull", field_name_pascal);

model_where_params.add_variant(
quote!(#is_null_variant),
quote! {
Self::#is_null_variant => (
#field_string,
#pcr::SerializedWhereValue::Object(vec![(
"equals".to_string(),
#pcr::PrismaValue::Null
)])
)
},
);

field_query_module.add_method(quote! {
pub fn disconnect() -> SetParam {
SetParam::#disconnect_variant
}

pub fn is_null() -> WhereParam {
WhereParam::#is_null_variant
}
});
}
}
Expand Down

0 comments on commit bebe1e7

Please sign in to comment.