Skip to content

Commit 9639a77

Browse files
committed
update
1 parent c618515 commit 9639a77

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

tests/e2e/orm/validation/toplevel.test.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createTestClient } from '@zenstackhq/testtools';
1+
import { createTestClient, loadSchemaWithError } from '@zenstackhq/testtools';
22
import Decimal from 'decimal.js';
33
import { 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
});

0 commit comments

Comments
 (0)