-
-
Notifications
You must be signed in to change notification settings - Fork 4k
fix(model): ensure $isDeleted is set after calling doc.deleteOne() successfully
#15898
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes an issue where doc.$isDeleted() was not being set to true after successfully calling doc.deleteOne(). The fix uses query.transform() to check the deletedCount property in the MongoDB result and sets $isDeleted(true) only when the deletion succeeds.
Key changes:
- Added
query.transform()hook inModel.prototype.deleteOne()to set$isDeleted(true)whendeletedCount > 0 - Added comprehensive tests covering successful deletion, failed deletion, and no-op behavior when already deleted
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| lib/model.js | Adds transform hook to set $isDeleted(true) after successful deleteOne operation |
| test/document.test.js | Adds tests verifying $isDeleted is set correctly after deleteOne, including success and failure cases |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
hasezoey
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, aside from what copilot brought up about the issue id in test name
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Hafez <[email protected]>
Fix #15858
Summary
Using
query.transform()instead ofquery.post()because Mongoose doesn't pass the result toquery.post(), and adding the result toquery.post()would be backwards breaking for cb-based post hooks.Examples