-
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.
fix(mongodb): warn when relation fields have diff native type (#3455)
- Loading branch information
Showing
10 changed files
with
156 additions
and
2 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
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
24 changes: 24 additions & 0 deletions
24
psl/psl/tests/validation/relations/mongodb/relation_same_native_type_1.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,24 @@ | ||
datasource db { | ||
provider = "mongodb" | ||
url = "mongodb://" | ||
} | ||
|
||
model Parent { | ||
id String @id @default(auto()) @map("_id") @db.ObjectId | ||
childId String @unique | ||
child Child? @relation(fields: [childId], references: [parentId]) | ||
} | ||
|
||
model Child { | ||
id String @id @default(auto()) @map("_id") @db.ObjectId | ||
parentId String @unique @db.ObjectId | ||
parent Parent? | ||
} | ||
// [1;93mwarning[0m: [1mWarning validating field `child` in model `Parent`: Field Parent.childId and Child.parentId must have the same native type for MongoDB to join those collections correctly. Consider either removing Child.parentId's native type attribute or adding '@db.ObjectId' to Parent.childId. Beware that this will become an error in the future.[0m | ||
// [1;94m-->[0m [4mschema.prisma:9[0m | ||
// [1;94m | [0m | ||
// [1;94m 8 | [0m | ||
// [1;94m 9 | [0m [1;93mchildId String @unique[0m | ||
// [1;94m10 | [0m child Child? @relation(fields: [childId], references: [parentId]) | ||
// [1;94m | [0m |
25 changes: 25 additions & 0 deletions
25
psl/psl/tests/validation/relations/mongodb/relation_same_native_type_2.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,25 @@ | ||
datasource db { | ||
provider = "mongodb" | ||
url = "mongodb://" | ||
} | ||
|
||
model Parent { | ||
id String @id @default(auto()) @map("_id") @db.ObjectId | ||
childId String @unique @db.ObjectId | ||
child Child? @relation(fields: [childId], references: [parentId]) | ||
} | ||
|
||
model Child { | ||
id String @id @default(auto()) @map("_id") @db.ObjectId | ||
parentId String @unique | ||
parent Parent? | ||
} | ||
|
||
// [1;93mwarning[0m: [1mWarning validating field `child` in model `Parent`: Field Parent.childId and Child.parentId must have the same native type for MongoDB to join those collections correctly. Consider either removing Parent.childId's native type attribute or adding '@db.ObjectId' to Child.parentId. Beware that this will become an error in the future.[0m | ||
// [1;94m-->[0m [4mschema.prisma:9[0m | ||
// [1;94m | [0m | ||
// [1;94m 8 | [0m | ||
// [1;94m 9 | [0m [1;93mchildId String @unique @db.ObjectId[0m | ||
// [1;94m10 | [0m child Child? @relation(fields: [childId], references: [parentId]) | ||
// [1;94m | [0m |
25 changes: 25 additions & 0 deletions
25
psl/psl/tests/validation/relations/mongodb/relation_same_native_type_3.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,25 @@ | ||
datasource db { | ||
provider = "mongodb" | ||
url = "mongodb://" | ||
} | ||
|
||
model Parent { | ||
id String @id @default(auto()) @map("_id") @db.ObjectId | ||
childId String @unique @db.ObjectId | ||
child Child? @relation(fields: [childId], references: [parentId]) | ||
} | ||
|
||
model Child { | ||
id String @id @default(auto()) @map("_id") @db.ObjectId | ||
parentId String @unique @db.String | ||
parent Parent? | ||
} | ||
|
||
// [1;93mwarning[0m: [1mWarning validating field `child` in model `Parent`: Field Parent.childId and Child.parentId must have the same native type for MongoDB to join those collections correctly. Consider updating those fields to either use '@db.ObjectId' or '@db.String'. Beware that this will become an error in the future.[0m | ||
// [1;94m-->[0m [4mschema.prisma:9[0m | ||
// [1;94m | [0m | ||
// [1;94m 8 | [0m | ||
// [1;94m 9 | [0m [1;93mchildId String @unique @db.ObjectId[0m | ||
// [1;94m10 | [0m child Child? @relation(fields: [childId], references: [parentId]) | ||
// [1;94m | [0m |