Repository navigation
fix(orm): resolve rows before simulating delegate cascades from regular models - #2878
Conversation
…ar models
Delete on a regular model with relations to delegate sub models deleted the children
with a relation filter before evaluating the parent's own filter. A filter that depends
on those children, such as `notes: { some: {} }`, then matched nothing and the parent
survived after its children were gone.
Route regular models through the same path as delegate models: read the matching rows
first, cascade into children by id, then delete the parents by id. This also lifts the
limit restriction for regular models. Rows hidden by the read policy are now skipped
consistently, which was already the documented behavior for delegate models.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
Follow-up to #2872.
Problem
BaseOperationHandler.deleteon a regular model with relations to delegate sub models deleted the children with a relation filter ({ [opposite]: where }) before evaluating the parent's ownwhere. A filter that depends on those children then matched nothing after they were gone:#2872 fixed the same ordering for delegate models by resolving the rows first, but kept the old order for regular models. This was pre-existing on
devbefore #2872 as well.Fix
Remove the separate regular-model branch and route every model with delegate cascade relations through the same path: read the matching rows first, cascade into children by id, then delete the parents by id. The discriminator column is only selected when the model has one.
Behavior changes
deleteManywithlimitnow works on a regular model with such relations instead of throwing.Tests
deletes non-delegate rows filtered by the related rows it cascades toindelegate-cascade-delete.test.ts. Fails ondevwithcount: 0, passes here.skips rows that can be deleted but not read.delegate-cascade-delete,delete,delegate,update,policy/delegate,policy/crud/deletee2e suites pass on SQLite (73 tests). Regression suite passes (268 tests). ORM unit tests pass.🤖 Generated with Claude Code
Summary by CodeRabbit