Skip to content

Commit

Permalink
NEXT-31890 - Fix one to many associations mapped length evaluation bu…
Browse files Browse the repository at this point in the history
…lk-edit-base.handler.js

```
if (mappedExistAssociations.hasOwnProperty(key)) {
  mappedExistAssociations[key].push(association);
 }
```
leads to evaluation errors at  `if (existAssociations.total > Object.keys(mappedExistAssociations).length)` as the mappedExistAssociations will never be === existAssociations.total. Thus the associations must be counted, otherwise there will be infinite requests.
fixes shopware#3328
  • Loading branch information
LunaDotGit authored and tamvt committed Nov 22, 2023
1 parent ac02642 commit 38032d6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
10 changes: 10 additions & 0 deletions changelog/_unreleased/2023-09-27-fix-one-to-many-bulk-edit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: Fix Bulk Edit one to many associations length evaluation and infinite requests
issue: NEXT-31890
author: Lily Berkow
author_email: [email protected]
author_github: TheAnimeGuru
---
# Administration
* Added `mappedExistAssociationsLen` which counts all arrays within `mappedExistAssociations` at each key entry
* Changed if for the recursion to not use `Object.keys(mappedExistAssociations).length` but the nested accounted length from `mappedExistAssociationsLen`
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,11 @@ class BulkEditBaseHandler {
}
});

if (existAssociations.total > Object.keys(mappedExistAssociations).length) {
// Associations at key can be more than one, so they must be counted properly
const mappedExistAssociationsLen =
Object.keys(mappedExistAssociations).reduce((acc, key) => acc + mappedExistAssociations[key].length, 0);

if (existAssociations.total > mappedExistAssociationsLen) {
return this._fetchOneToManyAssociated(fieldDefinition, change, page + 1, mappedExistAssociations);
}

Expand Down

0 comments on commit 38032d6

Please sign in to comment.