On delete cascade with doctrine2

There are two kinds of cascades in Doctrine:

1) ORM level – uses cascade={"remove"} in the association – this is a calculation that is done in the UnitOfWork and does not affect the database structure. When you remove an object, the UnitOfWork will iterate over all objects in the association and remove them.

2) Database level – uses onDelete="CASCADE" on the association’s joinColumn – this will add On Delete Cascade to the foreign key column in the database:

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

I also want to point out that the way you have your cascade={“remove”} right now, if you delete a Child object, this cascade will remove the Parent object. Clearly not what you want.

Leave a Comment