cascade={"remove"} VS orphanRemoval=true VS ondelete="CASCADE

onDelete="CASCADE" is managed by the database itself. cascade={"remove"} is managed by doctrine.

onDelete="CASCADE" is faster because the operations are performed on database level instead by doctrine. The removing is performed by the database server and not Doctrine. With cascade={"remove"} doctrine has to manage the entity itself and will perform extra checks to see if it doesn't have any other owning entities. When no other exists it will delete the entity. But this creates overhead.


cascade={"remove"}

  • the entity on the inverse side is deleted when the owning side entity is. Even if you are in a manytomany with other owning side entity. No, if the entity is owned by something else. It won't be deleted.
  • should be used on collection (so in OneToMany or ManyToMany relationship)
  • implementation in the ORM

orphanRemoval="true"

  • 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. Not exactly, this makes doctrine behave like it is not owned by an other entity, and thus remove it.
  • implementation in the ORM
  • can be used with OneToOne, OnetoMany or ManyToMany

onDelete="CASCADE"

  • this will add On Delete Cascade to the foreign key column IN THE DATABASE
  • This strategy is a bit tricky to get right but can be very powerful and fast. (this is a quote from doctrine official tutorial... but haven't seen much more explaination)
  • ORM has to do less work (compared to the two previous way of doing) and therefore should have better performance.