-
-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(delegate): null reference when reading an optional relation (#1491)
- Loading branch information
Showing
2 changed files
with
76 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { loadSchema } from '@zenstackhq/testtools'; | ||
describe('issue 1483', () => { | ||
it('regression', async () => { | ||
const { enhance } = await loadSchema( | ||
` | ||
model User { | ||
@@auth | ||
id String @id | ||
edits Edit[] | ||
@@allow('all', true) | ||
} | ||
model Entity { | ||
id String @id @default(cuid()) | ||
name String | ||
edits Edit[] | ||
type String | ||
@@delegate(type) | ||
@@allow('all', true) | ||
} | ||
model Person extends Entity { | ||
} | ||
model Edit { | ||
id String @id @default(cuid()) | ||
authorId String? | ||
author User? @relation(fields: [authorId], references: [id], onDelete: Cascade, onUpdate: NoAction) | ||
entityId String | ||
entity Entity @relation(fields: [entityId], references: [id], onDelete: Cascade, onUpdate: NoAction) | ||
@@allow('all', true) | ||
} | ||
` | ||
); | ||
|
||
const db = enhance(); | ||
await db.edit.deleteMany({}); | ||
await db.person.deleteMany({}); | ||
await db.user.deleteMany({}); | ||
|
||
const person = await db.person.create({ | ||
data: { | ||
name: 'test', | ||
}, | ||
}); | ||
|
||
await db.edit.create({ | ||
data: { | ||
entityId: person.id, | ||
}, | ||
}); | ||
|
||
await expect( | ||
db.edit.findMany({ | ||
include: { | ||
author: true, | ||
entity: true, | ||
}, | ||
}) | ||
).resolves.toHaveLength(1); | ||
}); | ||
}); |