title: Understanding Doctrine Cascade Operations
body: <p>I want to check my understanding of cascade operations on Doctrine associations. For the purpose of this question, I have two models: <code>Customer</code> and <code>Insuree</code>.</p>
  
  <p>If I define a many to many relationship between a <code>Customer</code> and <code>Insuree</code> and set <code>cascade{"all"}</code>, I understand that this will:</p>
  
  <ul>
  <li>Adding a new insuree to a customer will persist this insuree and create an association in the join table.</li>
  <li>Removing an insuree from the collection will detach the insuree from the customer and detach the customer from the insuree.</li>
  <li>Deleting the customer will delete all insurees associated with the customer.</li>
  </ul>
  
  <p>This is the definition of the association on <code>Customers</code>.</p>
  
  <pre><code>/**
   * @ORM\ManyToMany(targetEntity="Insuree", inversedBy="customers", cascade={"all"})
   * @ORM\JoinTable(name="customer_insuree",
   *      joinColumns={@ORM\JoinColumn(name="customer_id", referencedColumnName="id")},
   *      inverseJoinColumns={@ORM\JoinColumn(name="insuree_id", referencedColumnName="id")}
   * )
   */
  protected $insurees;
  </code></pre>
  
  <p>If I define the inverse many to many relationship between an <code>Insuree</code> and <code>Customer</code> and set <code>cascade{"all"}</code>, I understand that this will:</p>
  
  <ul>
  <li>Adding a new customer to an insuree will persist this customer and create an association in the join table.</li>
  <li>Removing a customer from the collection will detach the customer from the insuree and detach the insuree from the customer.</li>
  <li>Deleting the insuree will delete all customers associated with it.</li>
  </ul>
  
  <p>This is the definition of the association on <code>Insurees</code>.</p>
  
  <pre><code>/**
   * @ORM\ManyToMany(targetEntity="Customer", mappedBy="insurees", cascade={"all"})
   */
  protected $customers;
  </code></pre>
  
  <p>If I then define the relationship as to cascade on persist, merge and detach - deleting the insuree will not delete all associated customers - it will only remove the associations between the insuree and its customers?</p>
  
  <pre><code>/**
   * @ORM\ManyToMany(targetEntity="Customer", mappedBy="insurees", cascade={"persist", "merge", "detach"})
   */
  protected $customers;
  </code></pre>