Symfony: ManyToMany relation with self reference

Creating a many to many relation with self reference is straight forward (see docs). However I had to edit the „getFriendsWithMe“ method to get friends for ALL users (the original user where the friends are added and vice versa: The „new“ friends of the user should also display the original user as their friend):

public function getFriendsWithMe()
{
  return new ArrayCollection(
    array_merge(array_merge($this->friendsWithMe->toArray(), $this->myFriends->toArray()))
  );
}

Without the editing, I only got the original user to show his new friends but the new friends never showed the original user as their friend.

November 17th, 2017