according to the post Implementing a friends list in Symfony2.1 with Doctrine, i implemented the solution of @Roberto Trunfio.
/**
* @ORM\ManyToMany(targetEntity="User", mappedBy="friends")
*/
private $friendsWithMe;
/**
* @ORM\ManyToMany(targetEntity="User", inversedBy="friendsWithMe")
* @ORM\JoinTable(name="friends",
* joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="friend_user_id", referencedColumnName="id")}
* )
*/
private $friends;
It works, however I would like to go further by adding extra fields like 'senders, receiver, status, sendingDate...' but I don't know how to integrate it. Can somebody help me please ? Thanks
If you want to decorate the association with additional attributes, you need an association class. From the documentation (scroll down a bit):
The association class in your example is friendship. A user can have many friends and a user can be the friend of many users. Or more technically: A user has many friendships and many friendships map to a friend. In the example given below,
Friendship
has the additional attribute$hasBeenHelpful
(which is unsymmetrical indeed).And the friendship association:
You probably want to add some functions to the User class, such as