Skip to content

[Studio][Data Objects] Batch edit "Add"/"Remove" on advanced many-to-many relations discards all existing relations #451

Description

@MomodouBerlemann

Affected Version

2026.2

Affected capability

Data Objects

Steps to reproduce

Reproduced with pimcore/studio-backend-bundle v2026.1.6 + studio-ui-bundle v2026.1.6. The affected code is byte-identical in v2026.2.8 and on the 2026.x branch (last change to the file: July 2025), so the bug is still present on the latest release. Sub-area: data object listing → batch edit → advanced relations (advancedManyToManyObjectRelation, advancedManyToManyRelation).

  1. Create a class Item and a class Container with a field items of type Advanced Many-To-Many Object Relation (allowed class Item, one metadata column, e.g. text column note).
  2. Create items X, Y, Z and a container A with items = [X, Y]. Save.
  3. Open the listing of the folder containing A, select A, open Batch edit, add the field items.
  4. Choose mode "Add" (batch-edit.append-mode.add), select Z, run the batch edit.
  5. Open A again.

Actual Behavior

A.items now contains only Z. X and Y are gone. Mode "Remove" with Z empties the field completely (X and Y are removed although they were not part of the removal set). Mode "Replace" behaves as expected. The same batch edit on a plain manyToManyObjectRelation field appends/removes correctly.

Root cause: RelationDataService::getRelationExistingData() returns the wrong variable for advanced relations. The loop normalises $existingValues in place, but the method returns $existingData, which is still the empty array it was initialised with:

https://github.com/pimcore/studio-backend-bundle/blob/4e0e689be2cbafdb2462c43a41a5f22a8b435e0d/src/DataObject/Service/Data/RelationDataService.php#L109-L127

private function getRelationExistingData(array $existingValues, bool $isAdvanced): array
{
    $existingData =[];
    if ($isAdvanced) {
        foreach ($existingValues as $index => $existingRelation) {
            $existingValues[$index][ElementTypes::TYPE_ELEMENT] = $this->getExistingElementData(
                $existingRelation[ElementTypes::TYPE_ELEMENT]
            );
        }

        return $existingData; // always []
    }
    ...
}

PatchService::handlePatchDataField() therefore receives an empty $existingValues for every advanced relation. ADD becomes "set to the new entries only", REMOVE becomes "set to empty". The non-advanced branch of the same method (below the if) fills $existingData correctly, which is why plain relations are unaffected.

Expected Behavior

"Add" appends the selected elements to the existing relations, keeping existing metadata. "Remove" removes only the selected elements. Both consistent with the plain manyToManyObjectRelation behaviour and with Pimcore\Model\DataObject\ClassDefinition\Data\Relations\AbstractRelations::appendData() / removeData() in core.

One-line fix in the advanced branch:

return $existingValues;

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Fields

    Platform Version

    2026.2

    Affected capability

    Data Objects

    Galaxy

    None yet

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions