fix(database): process deleteMany relation filters via query init#25590
fix(database): process deleteMany relation filters via query init#25590sirrodgepodge wants to merge 1 commit intostrapi:developfrom
Conversation
|
@sirrodgepodge is attempting to deploy a commit to the Strapi Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug (issue #11998) where deleteMany would fail when filtering by a nested related entity. The root cause was that deleteMany used .where(where) directly on the query builder, which simply pushed raw conditions without processing relation attributes. By switching to .init({ where }), the query builder's processWhere step is triggered during processState(), which creates the necessary JOIN for relation attributes. With joins present on a delete-type query, the builder correctly routes through shouldUseSubQuery() → runSubQuery(), which constructs a safe subquery-based delete — enabling nested entity filtering to work as expected.
Changes:
- Replace
.where(where)with.init({ where })indeleteManyto align with howfindOne,findMany, andcountinitialize their query builders, ensuring relation-basedwherefilters are fully processed before execution.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Thanks for the PR! I took a quick look at this and while I would prefer to use Do you have a test case (either manual or an automated test) I can try to see if this fixes the referenced issue? |
Summary
deleteManyto initialize the query builder with{ where }via.init(...)Context
Issue: #11998 (
deleteManynot working when filtering by nested entity)Previously
deleteManyused.where(where)directly. Switching to.init({ where })aligns it with the pattern used in other query paths and ensures where params are fully initialized before delete.