From: Raphaƫl Gertz Date: Tue, 27 Feb 2024 15:31:55 +0000 (+0100) Subject: Fix subscriber user add/remove from inverse side X-Git-Tag: 0.3.0~65 X-Git-Url: https://git.rapsys.eu/airbundle/commitdiff_plain/a19fbcfc503a73d83e1fb7213a5e566fedfb3454?hp=fbe17cd04f8a37876254f2fdcb90566b05671a47 Fix subscriber user add/remove from inverse side --- 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); }