Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(database): process deleteMany relation filters via query init#25590

Open
sirrodgepodge wants to merge 1 commit intostrapi:developfrom
sirrodgepodge:fix-deleteMany-nested-relation-filter
Open

fix(database): process deleteMany relation filters via query init#25590
sirrodgepodge wants to merge 1 commit intostrapi:developfrom
sirrodgepodge:fix-deleteMany-nested-relation-filter

Conversation

@sirrodgepodge
Copy link

@sirrodgepodge sirrodgepodge commented Mar 1, 2026

Summary

  • fix deleteMany to initialize the query builder with { where } via .init(...)
  • ensures nested relation filters are processed consistently before delete execution

Context

Issue: #11998 (deleteMany not working when filtering by nested entity)

Previously deleteMany used .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.

Copilot AI review requested due to automatic review settings March 1, 2026 07:50
@vercel
Copy link

vercel bot commented Mar 1, 2026

@sirrodgepodge is attempting to deploy a commit to the Strapi Team on Vercel.

A member of the Team first needs to authorize it.

@strapi-cla
Copy link

strapi-cla commented Mar 1, 2026

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions bot added the community Changes and fixes created by community members label Mar 1, 2026
@dosubot dosubot bot added pr: fix This PR is fixing a bug source: core:database Source is core/database package labels Mar 1, 2026
Copy link

Copilot AI left a 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 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 }) in deleteMany to align with how findOne, findMany, and count initialize their query builders, ensuring relation-based where filters are fully processed before execution.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@innerdvations
Copy link
Contributor

innerdvations commented Mar 2, 2026

Thanks for the PR! I took a quick look at this and while I would prefer to use init since that's the pattern other methods here use, I couldn't reproduce any case where it actually fixed anything (and I'm hesitant to accept a core db change just for matching patterns with other methods).

Do you have a test case (either manual or an automated test) I can try to see if this fixes the referenced issue?

@innerdvations innerdvations self-assigned this Mar 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community Changes and fixes created by community members pr: fix This PR is fixing a bug source: core:database Source is core/database package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants