File tree Expand file tree Collapse file tree 2 files changed +53
-3
lines changed
Expand file tree Collapse file tree 2 files changed +53
-3
lines changed Original file line number Diff line number Diff line change @@ -250,7 +250,7 @@ export default class DataModelValidator implements AstValidator<DataModel> {
250250 return ;
251251 }
252252
253- if ( this . isFieldInheritedFromDelegateModel ( field ) ) {
253+ if ( this . isFieldInheritedFromDelegateModel ( field , contextModel ) ) {
254254 // relation fields inherited from delegate model don't need opposite relation
255255 return ;
256256 }
@@ -431,8 +431,8 @@ export default class DataModelValidator implements AstValidator<DataModel> {
431431 }
432432
433433 // checks if the given field is inherited directly or indirectly from a delegate model
434- private isFieldInheritedFromDelegateModel ( field : DataField ) {
435- return isDelegateModel ( field . $container ) ;
434+ private isFieldInheritedFromDelegateModel ( field : DataField , contextModel : DataModel ) {
435+ return field . $container !== contextModel && isDelegateModel ( field . $container ) ;
436436 }
437437
438438 private validateInherits ( model : DataModel , accept : ValidationAcceptor ) {
Original file line number Diff line number Diff line change @@ -114,4 +114,54 @@ describe('Delegate Tests', () => {
114114 'can only be applied once' ,
115115 ) ;
116116 } ) ;
117+
118+ it ( 'rejects relation missing the opposite side' , async ( ) => {
119+ await loadSchemaWithError (
120+ `
121+ datasource db {
122+ provider = 'sqlite'
123+ url = 'file:./dev.db'
124+ }
125+
126+ model A {
127+ id Int @id @default(autoincrement())
128+ b B @relation(fields: [bId], references: [id])
129+ bId Int
130+ type String
131+ @@delegate(type)
132+ }
133+
134+ model B {
135+ id Int @id @default(autoincrement())
136+ }
137+ ` ,
138+ 'missing an opposite relation' ,
139+ ) ;
140+
141+ await loadSchema (
142+ `
143+ datasource db {
144+ provider = 'sqlite'
145+ url = 'file:./dev.db'
146+ }
147+
148+ model A {
149+ id Int @id @default(autoincrement())
150+ b B @relation(fields: [bId], references: [id])
151+ bId Int
152+ type String
153+ @@delegate(type)
154+ }
155+
156+ model B {
157+ id Int @id @default(autoincrement())
158+ a A[]
159+ }
160+
161+ model C extends A {
162+ c String
163+ }
164+ ` ,
165+ ) ;
166+ } ) ;
117167} ) ;
You can’t perform that action at this time.
0 commit comments