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): allow inferring populate hint from filter via populate: ['$infer'] #4939

Merged
merged 1 commit into from
Nov 18, 2023

Conversation

B4nan
Copy link
Member

@B4nan B4nan commented Nov 18, 2023

If you want to automatically select all the relations that are part of your filter query, use populate: ['$infer']:

// this will populate all the books and their authors, all via a single query
const tags = await em.find(BookTag, {
  books: { author: { name: '...' } },
}, {
  populate: ['$infer'],
});

This will always use joined strategy as we already have the relations joined because they are in the filter.

Closes #1309

Copy link

codecov bot commented Nov 18, 2023

Codecov Report

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

Comparison is base (aaa3d4e) 99.42% compared to head (080216a) 99.43%.

Files Patch % Lines
packages/knex/src/query/QueryBuilder.ts 93.75% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4939   +/-   ##
=======================================
  Coverage   99.42%   99.43%           
=======================================
  Files         222      222           
  Lines       16037    16052   +15     
  Branches     3850     3851    +1     
=======================================
+ Hits        15945    15961   +16     
+ Misses         89       88    -1     
  Partials        3        3           

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

@B4nan B4nan force-pushed the populate-infer branch 2 times, most recently from 7a15ba6 to 19f0645 Compare November 18, 2023 14:41
…['$infer']`

If you want to automatically select all the relations that are part of your filter query, use `populate: ['$infer']`:

```ts
// this will populate all the books and their authors, all via a single query
const tags = await em.find(BookTag, {
  books: { author: { name: '...' } },
}, {
  populate: ['$infer'],
});
```

> This will always use joined strategy as we already have the relations joined because they are in the filter.

Closes #1309
@B4nan B4nan merged commit 080fdbb into master Nov 18, 2023
10 of 11 checks passed
@B4nan B4nan deleted the populate-infer branch November 18, 2023 15:15
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.

Allow auto-populate (via flag) of entities where the entity is used in the filtering criteria
1 participant