From a19fbcfc503a73d83e1fb7213a5e566fedfb3454 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Gertz?= Date: Tue, 27 Feb 2024 16:31:55 +0100 Subject: [PATCH 1/1] Fix subscriber user add/remove from inverse side --- Entity/User.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Entity/User.php b/Entity/User.php index 387b196..807fece 100644 --- a/Entity/User.php +++ b/Entity/User.php @@ -347,6 +347,9 @@ class User extends BaseUser { * @return User */ public function addSubscriber(User $subscriber): User { + //Add from owning side + $subscriber->addSubscription($this); + $this->subscribers[] = $subscriber; return $this; @@ -358,6 +361,13 @@ class User extends BaseUser { * @param User $subscriber */ public function removeSubscriber(User $subscriber): bool { + if (!$this->subscriptions->contains($subscriber)) { + return true; + } + + //Remove from owning side + $subscriber->removeSubscription($this); + return $this->subscribers->removeElement($subscriber); } @@ -378,9 +388,6 @@ class User extends BaseUser { * @return User */ public function addSubscription(User $subscription): User { - //Add from owning side - $subscription->addSubscriber($this); - $this->subscriptions[] = $subscription; return $this; @@ -392,13 +399,6 @@ class User extends BaseUser { * @param User $subscription */ public function removeSubscription(User $subscription): bool { - if (!$this->users->contains($user)) { - return true; - } - - //Remove from owning side - $subscription->removeSubscriber($this); - return $this->subscriptions->removeElement($subscription); } -- 2.41.1