My problem is simple:
I have Users and Stories in a many to many relationship, I would like to store a couple of attribute in the UserStory relationship:
- Priority (In order to set the ordering of the display for a given user)
- Main (flags which one is the main story)
How can I do that ?
Let say we have the following :
<?php
/** @Entity */
class User
{
// ...
/**
* @ManyToMany(targetEntity="Story", inversedBy="users")
* @JoinTable(name="users_stories")
*/
private $stories;
public function __construct() {
$this->stories = new \Doctrine\Common\Collections\ArrayCollection();
}
// ...
}
/** @Entity */
class Story
{
// ...
/**
* @ManyToMany(targetEntity="User", mappedBy="stories")
*/
private $users;
public function __construct() {
$this->users = new \Doctrine\Common\Collections\ArrayCollection();
}
// ...
}
?>
As Crozin suggested, this question is a duplicate of:
In my specific case the solution is simple. The Many-To-Many relationship needs to be build by hand, and extra fields need to be added manually. So two OneToMany relationship need to be build.
So here are my 3 objects and the associated meta information for each attribute: