Skip to content

Commit

Permalink
some more fixes for fixes prisma/prisma#2387
Browse files Browse the repository at this point in the history
  • Loading branch information
mavilein committed May 22, 2020
1 parent e062c94 commit e7841a6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
5 changes: 4 additions & 1 deletion libs/datamodel/core/src/validator/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,10 @@ impl<'a> Validator<'a> {
}
}

if rel_info.fields.len() != rel_info.to_fields.len() {
if !rel_info.fields.is_empty()
&& !rel_info.to_fields.is_empty()
&& rel_info.fields.len() != rel_info.to_fields.len()
{
errors.push(DatamodelError::new_directive_validation_error(
&format!("You must specify the same number of fields in `fields` and `references`.",),
RELATION_DIRECTIVE_NAME,
Expand Down
11 changes: 6 additions & 5 deletions libs/datamodel/core/tests/directives/relations_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,16 +293,17 @@ fn relation_must_error_when_referenced_fields_are_multiple_uniques() {
}
model Post {
id Int @id
text String
userName Int
id Int @id
text String
userId Int
userName String
// the relation is referencing two uniques. That is too much.
user User @relation(fields: [userName], references: [id, firstName])
user User @relation(fields: [userId, userName], references: [id, firstName])
}
"#;

let errors = parse_error(dml);
errors.assert_is(DatamodelError::new_validation_error("The argument `references` must refer to a unique criteria in the related model `User`. But it is referencing the following fields that are not a unique criteria: id, firstName", Span::new(261, 330)));
errors.assert_is(DatamodelError::new_validation_error("The argument `references` must refer to a unique criteria in the related model `User`. But it is referencing the following fields that are not a unique criteria: id, firstName", Span::new(298, 375)));
}

#[test]
Expand Down

0 comments on commit e7841a6

Please sign in to comment.