Sorry if the heading doesn’t make much sense, if you have a suggestion for a more accurate description of my problem, suggest it.
I am working on a Symfony 2 application, and I have User objects that should relate to another user, a simple use case that is friends, but there are more complicated cases. Initially, I had a lot of different relationships between users, and life was great.
Now I need to track metadata by the very relationship between the two users, for example:
- when the request was requested
- when he was adopted
- when it ended.
- if it is over, there are blocks to prevent the reopening of this relationship.
- and etc.
I have done quite a bit of research, and it seems that with the Doctrine I cannot have metadata about the relationships themselves, because they are not entities. It has been suggested that I use the average person object, so users have a many-to-many relationship with the Friendship object. The friendship object contains metadata and links to two users.
Now to my problem, if I have this friendship object, how do I get the other side? I have a function that I pass to a user that I know, so I get another user? One of the ways I thought about implementing this is below, but it seems to me that there should be a different way
$user = $this->getCurrentUser(); $friends = array(); foreach($user->getFriends() as $friendship) { $friends[] = $friendship->not($user);
and $ friendship-> not ():
public function not($user) { return $this->user1===$user ? $this->user2 : $this->user1; }
source share