-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3298 from prisma/fix/set-null-validation
feat(validation): disallow `SetNull` referential action on required referenced fields
- Loading branch information
Showing
9 changed files
with
143 additions
and
240 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
psl/psl/tests/validation/relations/set_null_is_not_valid_on_mixed_fields.prisma
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
model SomeUser { | ||
id Int @id | ||
ref Int | ||
profile Profile? | ||
@@unique([id, ref]) | ||
} | ||
|
||
model Profile { | ||
id Int @id | ||
user SomeUser? @relation(fields: [user_id, user_ref], references: [id, ref], onUpdate: SetNull, onDelete: SetNull) | ||
user_id Int? | ||
user_ref Int | ||
@@unique([user_id, user_ref]) | ||
} | ||
// [1;91merror[0m: [1mError parsing attribute "@relation": The `onDelete` referential action of a relation must not be set to `SetNull` when a referenced field is required. | ||
// Either choose another referential action, or make the referenced fields optional.[0m | ||
// [1;94m-->[0m [4mschema.prisma:11[0m | ||
// [1;94m | [0m | ||
// [1;94m10 | [0m id Int @id | ||
// [1;94m11 | [0m [1;91muser SomeUser? @relation(fields: [user_id, user_ref], references: [id, ref], onUpdate: SetNull, onDelete: SetNull)[0m | ||
// [1;94m12 | [0m user_id Int? | ||
// [1;94m | [0m | ||
// [1;91merror[0m: [1mError parsing attribute "@relation": The `onUpdate` referential action of a relation must not be set to `SetNull` when a referenced field is required. | ||
// Either choose another referential action, or make the referenced fields optional.[0m | ||
// [1;94m-->[0m [4mschema.prisma:11[0m | ||
// [1;94m | [0m | ||
// [1;94m10 | [0m id Int @id | ||
// [1;94m11 | [0m [1;91muser SomeUser? @relation(fields: [user_id, user_ref], references: [id, ref], onUpdate: SetNull, onDelete: SetNull)[0m | ||
// [1;94m12 | [0m user_id Int? | ||
// [1;94m | [0m |
26 changes: 26 additions & 0 deletions
26
psl/psl/tests/validation/relations/set_null_is_not_valid_on_required_fields.prisma
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
model SomeUser { | ||
id Int @id | ||
profile Profile? | ||
} | ||
|
||
model Profile { | ||
id Int @id | ||
user SomeUser? @relation(fields: [user_id], references: [id], onUpdate: SetNull, onDelete: SetNull) | ||
user_id Int @unique | ||
} | ||
// [1;91merror[0m: [1mError parsing attribute "@relation": The `onDelete` referential action of a relation must not be set to `SetNull` when a referenced field is required. | ||
// Either choose another referential action, or make the referenced fields optional.[0m | ||
// [1;94m-->[0m [4mschema.prisma:8[0m | ||
// [1;94m | [0m | ||
// [1;94m 7 | [0m id Int @id | ||
// [1;94m 8 | [0m [1;91muser SomeUser? @relation(fields: [user_id], references: [id], onUpdate: SetNull, onDelete: SetNull)[0m | ||
// [1;94m 9 | [0m user_id Int @unique | ||
// [1;94m | [0m | ||
// [1;91merror[0m: [1mError parsing attribute "@relation": The `onUpdate` referential action of a relation must not be set to `SetNull` when a referenced field is required. | ||
// Either choose another referential action, or make the referenced fields optional.[0m | ||
// [1;94m-->[0m [4mschema.prisma:8[0m | ||
// [1;94m | [0m | ||
// [1;94m 7 | [0m id Int @id | ||
// [1;94m 8 | [0m [1;91muser SomeUser? @relation(fields: [user_id], references: [id], onUpdate: SetNull, onDelete: SetNull)[0m | ||
// [1;94m 9 | [0m user_id Int @unique | ||
// [1;94m | [0m |
10 changes: 10 additions & 0 deletions
10
psl/psl/tests/validation/relations/set_null_still_valid_on_optional_fields.prisma
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
model SomeUser { | ||
id Int @id | ||
profile Profile? | ||
} | ||
|
||
model Profile { | ||
id Int @id | ||
user SomeUser? @relation(fields: [user_id], references: [id], onUpdate: SetNull, onDelete: SetNull) | ||
user_id Int? @unique | ||
} |
Oops, something went wrong.