Skip to content

fix(query-builder): merge raw join results in qb.execute()#4825

Merged
B4nan merged 1 commit into
masterfrom
qb-merge-raw-results
Oct 15, 2023
Merged

fix(query-builder): merge raw join results in qb.execute()#4825
B4nan merged 1 commit into
masterfrom
qb-merge-raw-results

Conversation

@B4nan
Copy link
Copy Markdown
Member

@B4nan B4nan commented Oct 15, 2023

Previously, the qb.execute() method returned cartesian product when joining to-many relations. Now the results will be automatically merged, as if you would map the results via qb.getResult().

Closes #4816
Related #4741

Previously, the `qb.execute()` method returned cartesian product when joining to-many relations.
Now the results will be automatically merged, as if you would map the results via `qb.getResult()`.

Closes #4816
Related #4741
switch (prop.reference) {
case ReferenceType.ONE_TO_MANY:
case ReferenceType.MANY_TO_MANY:
map[pk][hint.field] = this.mergeJoinedResult<T>([...map[pk][hint.field], ...item[hint.field]], prop.targetMeta!, hint.children ?? []);

Check warning

Code scanning / CodeQL

Prototype-polluting assignment

This assignment may alter Object.prototype if a malicious '__proto__' string is injected from [library input](1).
break;
case ReferenceType.MANY_TO_ONE:
case ReferenceType.ONE_TO_ONE:
map[pk][hint.field] = this.mergeJoinedResult<T>([map[pk][hint.field], item[hint.field]], prop.targetMeta!, hint.children ?? [])[0];

Check warning

Code scanning / CodeQL

Prototype-polluting assignment

This assignment may alter Object.prototype if a malicious '__proto__' string is injected from [library input](1).
@codecov
Copy link
Copy Markdown

codecov Bot commented Oct 15, 2023

Codecov Report

All modified lines are covered by tests ✅

Files Coverage Δ
packages/core/src/utils/Utils.ts 99.40% <ø> (-0.03%) ⬇️
packages/knex/src/AbstractSqlDriver.ts 98.94% <100.00%> (-0.88%) ⬇️
packages/knex/src/query/QueryBuilder.ts 99.40% <100.00%> (+<0.01%) ⬆️

📢 Thoughts on this report? Let us know!.

@B4nan B4nan merged commit 5a28e9b into master Oct 15, 2023
@B4nan B4nan deleted the qb-merge-raw-results branch October 15, 2023 19:58
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.

2 participants