Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A <code>OneToOne</code> relationship is unique as it would mean that only one <code>person</code> could be assigned to one <code>location</code> and one <code>location</code> to one <code>person</code>.</p> <p>In your scenario you would want one <code>person</code> to have multiple locations and one <code>location</code> could have multiple <code>person</code>(s). This would be a <code>ManyToMany</code> relationship. </p> <p>In Doctrine when you use a <code>ManyToMany</code> you will specify a <code>JoinTable</code> that Doctrine will manage (You don't have to create an entity for a <code>JoinTable</code>). The <code>JoinTable</code> breaks down the <code>ManyToMany</code> to something like a <code>OneToMany</code> such as one <code>person</code> to many <code>location</code>(s) as shown in example below. The <code>JoinTable</code> will store the values you want when they apply.</p> <pre><code>/** * @ORM\ManyToMany(targetEntity="Location") * @ORM\JoinTable(name="hometown_location", * joinColumns={@ORM\JoinColumn(name="person_id", referencedColumnName="id", unique=true)}, * inverseJoinColumns={@ORM\JoinColumn(name="location_id", referencedColumnName="id")} * ) **/ protected $hometown; /** * @ORM\ManyToMany(targetEntity="Location") * @ORM\JoinTable(name="current_location", * joinColumns={@ORM\JoinColumn(name="person_id", referencedColumnName="id", unique=true)}, * inverseJoinColumns={@ORM\JoinColumn(name="location_id", referencedColumnName="id")} * ) **/ protected $current; public function __construct() { $this-&gt;hometown = new \Doctrine\Common\Collections\ArrayCollection(); $this-&gt;hometown = new \Doctrine\Common\Collections\ArrayCollection(); } </code></pre> <p>If there is no <code>location</code> to assign to <code>hometown</code> or <code>current</code> that is fine, no space is taken up. When you do have a <code>location</code> to assign to either <code>hometown</code> or <code>current</code> it will have to be a valid <code>location</code> from the <code>location</code> table.</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.
 

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