Doctrine 2 cascade={''remove"} doesn't seem to be working

Your relationship definition seems to be fine. What is the way the customer is deleted? I mean Doctrine doesn't set "ON DELETE CASCADE" directly in database. So, if you remove customer entity in other way than "doctrine's" one, comments won't be deleted.

You may tell doctrine to set this directly in database, by adding in annotation:

@ORM\JoinColumn(name="icustomer_id", referencedColumnName="icustomer_id", onDelete="CASCADE")

But if you're trying remove the entity in right-doctrine way ant this still doesn't work, try add "orphanRemoval" to true, it should help:

// Customer.php
/**
 * @var string $addresses
 * @ORM\OneToMany(targetEntity="MP\User\RegistrationBundle\Entity\Address", mappedBy="customer", cascade={"remove"}, orphanRemoval=true)
 */
protected $addresses;

I had quite a bit of trouble getting this to work. Here's some points that might help those having similar troubles:

  1. The owning entity needs @OneToMany( ... cascade={"remove"} or cascade={"all"} )
  2. The child entity also needs @JoinColumn(... onDelete="CASCADE")
  3. Also, if you are modifying the onDelete="CASCADE" part I believe you will need to update your schema before your changes take effect.

Tags:

Doctrine Orm