Skip to content

Commit

Permalink
dml: Infer not-available relation scalar fields as empty
Browse files Browse the repository at this point in the history
...instead of crashing. This is bad relation logic in dml that can't
really be fixed. The long term solution is to switch to rendering to the
AST.

closes prisma/prisma#11013
  • Loading branch information
tomhoule committed Jan 7, 2022
1 parent f0098a4 commit f48ae31
Showing 1 changed file with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,16 @@ impl<'ast> InlineRelationWalkerExt<'ast> for InlineRelationWalker<'ast, '_> {
fn constraint_name(self, connector: &dyn Connector) -> Cow<'ast, str> {
self.foreign_key_name().map(Cow::Borrowed).unwrap_or_else(|| {
let model_database_name = self.referencing_model().final_database_name();
match self.referencing_fields() {
ReferencingFields::Concrete(fields) => {
let field_names: Vec<&str> = fields.map(|f| f.database_name()).collect();
ConstraintNames::foreign_key_constraint_name(model_database_name, &field_names, connector).into()
}
let field_names: Vec<&str> = match self.referencing_fields() {
ReferencingFields::Concrete(fields) => fields.map(|f| f.database_name()).collect(),
ReferencingFields::Inferred(fields) => {
let field_names: Vec<&str> = fields.iter().map(|f| f.name.as_str()).collect();
ConstraintNames::foreign_key_constraint_name(model_database_name, &field_names, connector).into()
let field_names: Vec<_> = fields.iter().map(|f| f.name.as_str()).collect();
return ConstraintNames::foreign_key_constraint_name(model_database_name, &field_names, connector)
.into();
}
ReferencingFields::NA => unreachable!(),
}
ReferencingFields::NA => Vec::new(),
};
ConstraintNames::foreign_key_constraint_name(model_database_name, &field_names, connector).into()
})
}
}
Expand Down

0 comments on commit f48ae31

Please sign in to comment.