Uploaded image for project: 'Doctrine 2 - ORM'
  1. Doctrine 2 - ORM
  2. DDC-1098

Cascading delete is broken for all relationships other than inheritance relationships, at least on MySQL 5.0


    • Type: Bug
    • Status: Resolved
    • Priority: Critical
    • Resolution: Invalid
    • Affects Version/s: 2.1.1
    • Fix Version/s: 2.1.1
    • Component/s: ORM
    • Security Level: All
    • Labels:
    • Environment:
      Debian Linux 6.0, MySQL 5.0.51a


      The console tools do not generate the proper DDL statements for the constraints declared as part of the relationship annotations.

      Take this entity field declaration, e.g. :

        * @OneToMany(targetEntity="\persistentData\model\core\invoiceCreator\AnalogOrderInvoiceLineItem", mappedBy="partialInvoice", cascade={"persist", "remove", "detach"})
       protected $analogOrderInvoiceLineItems;

      This declaration should generate some sort of ON DELETE CASCADE constraint, or at least actually cascade the delete, in whatever way. It does not. I reviewed the generated DDL statements with

      doctrine orm:schema-tool:create --dump-sql

      And it clearly showed that no "ON DELETE CASCADE" was generated. Neither did Doctrine 2 perform a cascading delete otherwise.

      The delete simply does not cascade.

      Subsequently, I end up getting errors like:

      Exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails
      (`invoiceCreatorDB/AnalogOrderInvoiceLineItem`, CONSTRAINT `AnalogOrderInvoiceLineItem_ibfk_1` FOREIGN KEY (`partialInvoice_dbID`) REFERENCES `PartialInvoice` (`dbID`))'

      The query that caused the error is:

      DELETE FROM PartialInvoice where dbID = '2';

      (PartialInvoice is the entity containing the above field declaration).

      It seems that the cascading delete feature is fundamentally broken.



          • Assignee:
            beberlei Benjamin Eberlei
            dalvarez Daniel Alvarez Arribas
          • Votes:
            0 Vote for this issue
            0 Start watching this issue


            • Created: