Skip to content

fix(sql): handle $not nested under collection properties - #8471

Open
lazerg wants to merge 1 commit into
mikro-orm:masterfrom
lazerg:fix/issue-8468-nested-not-collection
Open

lazerg wants to merge 1 commit into
mikro-orm:masterfrom
lazerg:fix/issue-8468-nested-not-collection

Conversation

@lazerg

@lazerg lazerg commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

$not is a query operator, so a few places treated { $not: { name: 'blue' } } under a collection like { $in: [...] }, a condition on the relation itself, and not on the target entity.

For an M:N property, this joined only the pivot table and queried pivot.name, which fails with "no such column". In populateWhere, the select-in loader moved the $not under the target PK ({ id: { $not: { title: 'B' } } }), and that crashed in joinReference. With the joined strategy, the $not was dropped from the join's on clause, so the filter matched the opposite rows.

Now a $not that wraps entity conditions is handled like those conditions: the target entity gets joined, the loader keeps it on the target entity, and the joined strategy adds the whole $not to the join it targets.

Fixes #8468

@codecov

codecov Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.66%. Comparing base (733c05d) to head (3ba7502).

Additional details and impacted files
@@           Coverage Diff            @@
##           master    #8471    +/-   ##
========================================
  Coverage   99.66%   99.66%            
========================================
  Files         293      293            
  Lines       32172    32185    +13     
  Branches     9094     8686   -408     
========================================
+ Hits        32065    32078    +13     
  Misses        103      103            
  Partials        4        4            

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

$not nested under a collection property breaks the query

1 participant