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

Reverse relation remove on content save #2504

Closed
napley opened this issue Apr 1, 2021 · 1 comment · Fixed by #2535
Closed

Reverse relation remove on content save #2504

napley opened this issue Apr 1, 2021 · 1 comment · Fixed by #2535

Comments

@napley
Copy link
Contributor

napley commented Apr 1, 2021

Reverse relation remove on content save

Details

Install type: Packaged distribution
Database: mysql 5.5.62 - service.mysql via TCP/IP
PHP version: 7.4.11
Symfony version: v5.2.6
Operating System: Linux - 5.4.0-70-generic
Assets version: 4.1.16

Reproduction

On a contentA I define a relation:

contentA:
    //...
    relations:
        contentB:
            label: contentB
            required: false
            multiple: false

On a contentB I define a relation:

contentB:
    //...
    relations:
        contentC:
            label: contentC
            required: false
            multiple: false

When I save contentA with a contentB selected I see the relation in database.
After I save the contentB without or with a contentC selected, the relation between contentA and contentB is removed.

I see in the contentEditController, all the relation is removed before insert new:

//...
 private function updateRelation(Content $content, $newRelations): void
    {
        $newRelations = (new Collection(Json::findArray($newRelations)))->filter();
        $currentRelations = $this->relationRepository->findRelations($content, null, true, null, false);

        // Remove old ones
        foreach ($currentRelations as $currentRelation) {
            $this->em->remove($currentRelation);
        }
       //...

I understand why relation is removed but I don't understand why reverse relation are removed too.
So I made a fix which change the bidirectionnal attribute:
$currentRelations = $this->relationRepository->findRelations($content, null, false, null, false);

Do you think there will be side effect ?

The commit in my repo with the modification : novaway@35c7a6e

@I-Valchev
Copy link
Member

Hi @napley , sorry for taking a bit longer to respond to this...

I think your suggestion should work fine! Would you like to submit a PR for it under your name? ;-)

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 a pull request may close this issue.

2 participants