|
| 1 | +import { createPolicyTestClient } from '@zenstackhq/testtools'; |
| 2 | +import { describe, expect, it } from 'vitest'; |
| 3 | + |
| 4 | +describe('Regression for issue #2385', () => { |
| 5 | + it('should not generate "missing FROM-clause entry" when including a relation with a static-value @@allow policy', async () => { |
| 6 | + const db = await createPolicyTestClient( |
| 7 | + ` |
| 8 | +model User { |
| 9 | + id String @id @default(uuid()) |
| 10 | + name String |
| 11 | + associations Association[] |
| 12 | + createdAt DateTime @default(now()) |
| 13 | + updatedAt DateTime @updatedAt |
| 14 | +
|
| 15 | + @@allow("read", auth().id == id) |
| 16 | +} |
| 17 | +
|
| 18 | +model Association { |
| 19 | + id String @id @default(uuid()) |
| 20 | + name String |
| 21 | + userId String @db.VarChar @map("user_id") |
| 22 | + user User @relation(fields: [userId], references: [id]) |
| 23 | + createdAt DateTime @default(now()) @allow("read", auth().id == userId) |
| 24 | + updatedAt DateTime @updatedAt |
| 25 | +
|
| 26 | + @@allow("read", auth().id == userId) |
| 27 | +} |
| 28 | + `, |
| 29 | + ); |
| 30 | + |
| 31 | + const rawDb = db.$unuseAll(); |
| 32 | + const user = await rawDb.user.create({ |
| 33 | + data: { |
| 34 | + name: 'John Doe', |
| 35 | + }, |
| 36 | + }); |
| 37 | + |
| 38 | + await rawDb.association.create({ |
| 39 | + data: { |
| 40 | + name: 'Association for John', |
| 41 | + userId: user.id, |
| 42 | + }, |
| 43 | + }); |
| 44 | + |
| 45 | + const userDb = db.$setAuth(user); |
| 46 | + |
| 47 | + await expect( |
| 48 | + userDb.user.findMany({ |
| 49 | + include: { associations: true }, |
| 50 | + }), |
| 51 | + ).toResolveTruthy(); |
| 52 | + }); |
| 53 | +}); |
0 commit comments