This case cannot be solved with OneToMany associations.
You need 2 distinct relations between AssociationQuestion
and AssociationPossibleAnswer
. The way you've set it up, you only have 1 relation. Just look at the 1 ManyToOne association you created in AssociationPossibleAnswer
.
And you're trying to have 2 opposite sides of that 1 relation, which is theoretically impossible. A relation can only have 2 endpoints (not 3).
Solution
Implement 2 (unidirectional) ManyToMany associations in AssociationQuestion
, and make the foreign key pointing to AssociationPossibleAnswer
unique:
class AssociationQuestion
{
/**
* @ORM\ManyToMany(targetEntity="AssociationPossibleAnswer")
* @ORM\JoinTable(name="association_question_association_possible_answer_left",
* joinColumns={@ORM\JoinColumn(name="association_question_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="association_possible_answer_id", referencedColumnName="id", unique=true)}
* )
*/
private $possibleAnswersLeft;
/**
* @ORM\ManyToMany(targetEntity="AssociationPossibleAnswer")
* @ORM\JoinTable(name="association_question_association_possible_answer_right",
* joinColumns={@ORM\JoinColumn(name="association_question_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="association_possible_answer_id", referencedColumnName="id", unique=true)}
* )
*/
private $possibleAnswersRight;
// ...
Doctrine calls this a One-To-Many, Unidirectional with Join Table association.