Skip to content
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

feat(core): auto-join M:1 and 1:1 relations with filters #5063

Merged
merged 1 commit into from
Jan 1, 2024

Conversation

B4nan
Copy link
Member

@B4nan B4nan commented Jan 1, 2024

Filters are applied to the relations too, as part of JOIN ON condition. If a filter exists on a M:1 or 1:1 relation target, such an entity will be automatically joined, and when the foreign key is defined as NOT NULL, it will result in an INNER JOIN rather than LEFT JOIN. This is especially important for implementing soft deletes via filters, as the foreign key might point to a soft-deleted entity. When this happens, the automatic INNER JOIN will result in such a record not being returned at all.

You can disable this behavior via autoJoinRefsForFilters ORM option.

Related: #4975

Copy link

codecov bot commented Jan 1, 2024

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (8b57319) 99.78% compared to head (cf4df54) 99.78%.
Report is 1 commits behind head on master.

❗ Current head cf4df54 differs from pull request most recent head ff03f43. Consider uploading reports for the commit ff03f43 to get more accurate results

Files Patch % Lines
packages/knex/src/query/QueryBuilder.ts 91.66% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5063   +/-   ##
=======================================
  Coverage   99.78%   99.78%           
=======================================
  Files         221      221           
  Lines       16351    16384   +33     
  Branches     3936     3954   +18     
=======================================
+ Hits        16316    16349   +33     
  Misses         35       35           

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

Filters are applied to the relations too, as part of `JOIN ON` condition. If a filter exists on a M:1 or 1:1 relation target, such an entity will be automatically joined, and when the foreign key is defined as `NOT NULL`, it will result in an `INNER JOIN` rather than `LEFT JOIN`. This is especially important for implementing soft deletes via filters, as the foreign key might point to a soft-deleted entity. When this happens, the automatic `INNER JOIN` will result in such a record not being returned at all.

You can disable this behavior via `autoJoinRefsForFilters` ORM option.

Related: #4975
@B4nan B4nan merged commit 66a6b75 into master Jan 1, 2024
6 of 7 checks passed
@B4nan B4nan deleted the eager-join-filter branch January 1, 2024 15:03
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.

None yet

1 participant