From f1fc6f9ab3a9cb8a6ef16dc5f30de4cc0b6e8288 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 10 Oct 2022 13:47:17 +0200 Subject: [PATCH] Fixed: usage of owner side / inversed side on SocialAction / Evaluation In a ManyToMany relationship, doctrine does take care only of the owning side of a relationship to inspect changes. ([see documentation](https://www.doctrine-project.org/projects/doctrine-orm/en/current/reference/unitofwork-associations.html#important-concepts)) This commit mark as "internal" the methods add/removeSocialAction on the inversed side (`Evaluation`) and let the methods add/removeEvaluation on the owning side (`SocialAction`) update the inversed side. The usage is also adapted into SocialWorkMetadata's importer. --- .../ChillPersonBundle/Entity/SocialWork/Evaluation.php | 8 ++++++++ .../ChillPersonBundle/Entity/SocialWork/SocialAction.php | 2 ++ .../Service/Import/SocialWorkMetadata.php | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Bundle/ChillPersonBundle/Entity/SocialWork/Evaluation.php b/src/Bundle/ChillPersonBundle/Entity/SocialWork/Evaluation.php index 5c05fe683..3324a236f 100644 --- a/src/Bundle/ChillPersonBundle/Entity/SocialWork/Evaluation.php +++ b/src/Bundle/ChillPersonBundle/Entity/SocialWork/Evaluation.php @@ -72,6 +72,9 @@ class Evaluation $this->socialActions = new ArrayCollection(); } + /** + * @internal do use @see{SocialAction::addEvaluation} + */ public function addSocialAction(SocialAction $socialAction): self { if (!$this->socialActions->contains($socialAction)) { @@ -111,6 +114,11 @@ class Evaluation return $this->url; } + /** + * @return $this + * + * @internal do use @see{SocialAction::removeEvaluation} + */ public function removeSocialAction(SocialAction $socialAction): self { if ($this->socialActions->contains($socialAction)) { diff --git a/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialAction.php b/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialAction.php index bc81bc180..1607d385d 100644 --- a/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialAction.php +++ b/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialAction.php @@ -112,6 +112,7 @@ class SocialAction { if (!$this->evaluations->contains($evaluation)) { $this->evaluations[] = $evaluation; + $evaluation->addSocialAction($this); } return $this; @@ -310,6 +311,7 @@ class SocialAction public function removeEvaluation(Evaluation $evaluation): self { $this->evaluations->removeElement($evaluation); + $evaluation->removeSocialAction($this); return $this; } diff --git a/src/Bundle/ChillPersonBundle/Service/Import/SocialWorkMetadata.php b/src/Bundle/ChillPersonBundle/Service/Import/SocialWorkMetadata.php index 54308bc9c..f1050b134 100644 --- a/src/Bundle/ChillPersonBundle/Service/Import/SocialWorkMetadata.php +++ b/src/Bundle/ChillPersonBundle/Service/Import/SocialWorkMetadata.php @@ -193,7 +193,7 @@ final class SocialWorkMetadata implements SocialWorkMetadataInterface /** @var Evaluation $eval */ $eval = $this->getOrCreateEntity($this->evaluationRepository, 'title', ['fr' => $evaluationTitle]); $eval->setTitle(['fr' => $evaluationTitle]); - $eval->addSocialAction($socialAction); + $socialAction->addEvaluation($eval); $this->entityManager->persist($eval);