Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I ran into this same issue about a week ago. I polled the Doctrine IRC channel users for the best solution (or at least the one that's most commonly practiced). Here's how it's done:</p> <p>Create a new entity named something like EventsPeopleRoles with three properties mapped using @ManyToOne, $event, $person, and $role.</p> <p>Each association should be mapped similar to this:</p> <pre><code>/** * @ManyToOne(targetEntity="Events", inversedBy="eventsPeopleRoles") * @JoinColumn(name="event_id", referencedColumnName="id", nullable=false) */ private $event; </code></pre> <p>Then in each of the three related entities, code the inverse side of the association like this:</p> <pre><code>/** * @OneToMany(targetEntity="EventsPeopleRoles", mappedBy="event") */ private $eventsPeopleRoles; </code></pre> <p>You then have the choice of either adding an $id property to your "join entity" or using a composite primary key as described <a href="http://www.doctrine-project.org/docs/orm/2.1/en/tutorials/composite-primary-keys.html#identity-through-foreign-entities" rel="noreferrer">here</a> and adding a unique constraint annotation in the entity class definition. Note that composite foreign keys are only supported beginning in Doctrine 2.1.</p> <p>I was skeptical about this solution because I don't like the idea of creating an entity only for the purposes of a join. It seems like cheating or at least in contrast to ORM design principles. But I am confident this is the accepted solution (for now at least) among Doctrine experts.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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