Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I was getting this problem from a conflict with join table defined in an association class annotation and a join table defined in a ManyToMany annotation.</p> <p>The mapping definitions in two entities with a direct ManytoMany relationship appeared to result in the automatic creation of the join table using the 'joinTable' annotation. However the join table was already defined by an annotation in its underlying entity class and I wanted it to use this association entity class's own field definitions so as to extend the join table with additional custom fields.</p> <p>The explanation and solution was thanks to this post in the forum '<a href="http://forum.symfony-project.org/viewtopic.php?t=36745&amp;p=122235">Doctrine Annotation Question</a>'. This post draws attention to the Doctrine documentation regarding <a href="http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/association-mapping.html#many-to-many-unidirectional">ManyToMany Uni-directional relationships</a>. Look at the note regarding the approach of using an 'association entity class' thus replacing the many-to-many annotation mapping directly between two main entity classes with a one-to-many annotation in the main entity classes and two 'many-to-one' annotations in the Associative Entity class. There is an example provided in this forum post <a href="https://groups.google.com/forum/#!topic/doctrine-user/cw8fyH9_ebY">Association models with extra fields</a>:</p> <pre><code>public class Person { /** * @OneToMany(targetEntity="AssignedItems", mappedBy="person") */ private $assignedItems; } public class Items { /** * @OneToMany(targetEntity="AssignedItems", mappedBy="item") */ private $assignedPeople; } public class AssignedItems { /** * @ManyToOne(targetEntity="Person") * @JoinColumn(name="person_id", referencedColumnName="id") */ private $person; /** * @ManyToOne(targetEntity="Item") * @JoinColumn(name="item_id", referencedColumnName="id") */ private $item; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload