title: cascade={"remove"} VS orphanRemoval=true VS ondelete="CASCADE
body: <p>I tried to gather some information about the following way to delete automatically child entity when a parent entity is deleted. Seems that the most common way is to use one those three annotation: <code>cascade={&quot;remove&quot;}</code> OR <code>orphanRemoval=true</code> OR <code>ondelete=&quot;CASCADE&quot;</code>.</p>
  <p>I am a bit confused about the third one: <code>ondelete=&quot;CASCADE&quot;</code>, as the explanation in doctrine official documentation about this one are very scarce) and I would love if someone could <strong>confirm me the following information</strong> I gathered and understand from my research on the net and experience...</p>
  <p>What does it do?</p>
  <p><code>cascade={&quot;remove&quot;}</code>
  ==&gt; the entity on the inverse side is deleted when the owning side entity is. Even if you are in a <code>ManyToMany</code> with other owning side entity.</p>
  <ul>
  <li>should be used on collection (so in <code>OneToMany</code> or <code>ManyToMany</code> relationship)</li>
  <li>implementation in the ORM</li>
  </ul>
  <p><code>orphanRemoval=true</code>
  ==&gt; the entity on the inverse side is deleted when the owning side entity is AND it is not connected to any other owning side entity anymore. (ref.  <a href="http://doctrine-orm.readthedocs.org/en/latest/reference/xml-mapping.html?highlight=orphanremoval#defining-many-to-one-associations" rel="noreferrer">doctrine official_doc</a></p>
  <ul>
  <li>implementation in the ORM</li>
  <li>can be used with <code>OneToOne</code>, <code>OneToMany</code> or <code>ManyToMany</code></li>
  </ul>
  <p><code>onDelete=&quot;CASCADE&quot;</code>
  ==&gt; this will add On Delete Cascade to the foreign key column in the database</p>
  <ul>
  <li>This strategy is a bit tricky to get right but can be very powerful and fast. (ref.  <a href="http://doctrine-orm.readthedocs.org/en/latest/reference/working-with-objects.html?highlight=tricky#removing-entities" rel="noreferrer">doctrine official_doc</a> ... but haven't read more explanations)</li>
  <li>ORM has to do less work (compared to the two previous ways of doing it) and therefore should have better performance.</li>
  </ul>
  <p><strong>other information</strong></p>
  <ul>
  <li>all those 3 ways of doing are implemented on bidirectional relationship entities (<strong><em>right???</em></strong>)</li>
  <li>using <code>cascade={&quot;remove&quot;}</code> completely by-passes any foreign key onDelete=CASCADE. (ref. <a href="http://doctrine-orm.readthedocs.org/en/latest/reference/working-with-objects.html?highlight=tricky#removing-entities" rel="noreferrer">doctrine_official_doc</a>)</li>
  </ul>
  <h2>EXAMPLE ON HOW TO USE IT IN CODE</h2>
  <ul>
  <li><code>orphanRemoval</code> and <code>cascade={&quot;remove&quot;}</code> are defined in the inversed entity class.</li>
  <li><code>ondelete=&quot;CASCADE&quot;</code> is defined in the owner entity</li>
  <li>you can also just write <code>@ORM\JoinColumn(onDelete=&quot;CASCADE&quot;)</code> and let doctrine handle the column names</li>
  </ul>
  <p><strong>cascade={&quot;remove&quot;}</strong></p>
  <pre><code>/**
  * @OneToMany(targetEntity=&quot;Phonenumber&quot;, mappedBy=&quot;contact&quot;, cascade={&quot;remove&quot;})
  */
  protected $Phonenumbers
  </code></pre>
  <p><strong>orphanRemoval=true</strong></p>
  <pre><code>/**
  * @OneToMany(targetEntity=&quot;Phonenumber&quot;, mappedBy=&quot;contact&quot;, orphanRemoval=true)
  */
  protected $Phonenumbers
  </code></pre>
  <p><strong>onDelete=&quot;CASCADE&quot;</strong></p>
  <pre><code>/** 
  * @ManyToOne(targetEntity=&quot;Contact&quot;, inversedBy=&quot;phonenumbers&quot;)
  * @JoinColumn(name=&quot;contact_id&quot;, referencedColumnName=&quot;contact_id&quot;, onDelete=&quot;CASCADE&quot;)
  */ 
  protected $contact; 
  </code></pre>