Skip to content

Commit 27b890d

Browse files
committed
test(objectql): a predicate delete inherits the own-cascade restrict rule
Claude-Session: https://claude.ai/code/session_01FEkQ5ptsvnYe5ZErgvP66h Co-authored-by: Claude <noreply@anthropic.com>
1 parent 23fbbb2 commit 27b890d

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

‎packages/objectql/src/engine-cascade-delete-atomic.test.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,29 @@ describe('[#26871] a predicate delete runs the referential walk for every matche
537537
expect(driver.rowsOf('node').map((r: any) => [r.id, r.boss ?? null])).toEqual([[report.id, null]]);
538538
});
539539

540+
it('a detail that also restricts its own master refuses the predicate delete, as it does by id (#26718)', async () => {
541+
// The predicate arm runs the by-id walk itself, so every rule the walk
542+
// judges holds here too: the detail is in its master's cascade set by its
543+
// own master_detail, and its restrict to that master still refuses.
544+
const pledge = {
545+
name: 'pledge',
546+
label: 'Pledge',
547+
fields: {
548+
id: { name: 'id', type: 'text' as const, primaryKey: true },
549+
parent: { name: 'parent', type: 'master_detail' as const, reference: 'parent' },
550+
guard: { name: 'guard', type: 'lookup' as const, reference: 'parent', deleteBehavior: 'restrict' },
551+
},
552+
};
553+
const { engine, driver } = await makeEngine([parent, pledge]);
554+
const p = await engine.insert('parent', { name: 'doomed' });
555+
await engine.insert('pledge', { parent: p.id, guard: p.id });
556+
557+
await expect(engine.delete('parent', { where: { name: 'doomed' }, multi: true }))
558+
.rejects.toMatchObject({ code: 'DELETE_RESTRICTED', status: 409, dependentObject: 'pledge' });
559+
expect(driver.rowsOf('parent')).toHaveLength(1);
560+
expect(driver.rowsOf('pledge')).toHaveLength(1);
561+
});
562+
540563
it('a matched set of zero rows walks nothing and deletes nothing', async () => {
541564
const { engine, driver } = await makeEngine([parent, detail]);
542565
const p = await engine.insert('parent', { name: 'kept' });

0 commit comments

Comments
 (0)