File tree Expand file tree Collapse file tree 1 file changed +37
-1
lines changed Expand file tree Collapse file tree 1 file changed +37
-1
lines changed Original file line number Diff line number Diff line change 1- import { createTestClient } from '@zenstackhq/testtools' ;
1+ import { createTestClient , loadSchemaWithError } from '@zenstackhq/testtools' ;
22import Decimal from 'decimal.js' ;
33import { describe , expect , it } from 'vitest' ;
44
@@ -170,4 +170,40 @@ describe('Toplevel field validation tests', () => {
170170 // satisfies all
171171 await expect ( db . foo . create ( { data : { int1 : '3.3' , int2 : new Decimal ( 3.9 ) } } ) ) . toResolveTruthy ( ) ;
172172 } ) ;
173+
174+ it ( 'rejects accessing relation fields' , async ( ) => {
175+ await loadSchemaWithError (
176+ `
177+ model Foo {
178+ id Int @id @default(autoincrement())
179+ bars Bar[]
180+ @@validate(bars != null)
181+ }
182+
183+ model Bar {
184+ id Int @id @default(autoincrement())
185+ foo Foo @relation(fields: [fooId], references: [id])
186+ fooId Int
187+ }
188+ ` ,
189+ 'cannot use relation fields' ,
190+ ) ;
191+
192+ await loadSchemaWithError (
193+ `
194+ model Foo {
195+ id Int @id @default(autoincrement())
196+ bars Bar[]
197+ @@validate(bars.fooId > 0)
198+ }
199+
200+ model Bar {
201+ id Int @id @default(autoincrement())
202+ foo Foo @relation(fields: [fooId], references: [id])
203+ fooId Int
204+ }
205+ ` ,
206+ 'cannot use relation fields' ,
207+ ) ;
208+ } ) ;
173209} ) ;
You can’t perform that action at this time.
0 commit comments