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

    Details

    • 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:
      None
    • Environment:
      Debian Linux 6.0, MySQL 5.0.51a

      Description

      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.

        Activity

        dalvarez Daniel Alvarez Arribas created issue -
        dalvarez Daniel Alvarez Arribas made changes -
        Field Original Value New Value
        Description
        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

        {code}
        doctrine orm:schema-tool:create --dump-sql
        {code}

        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:

        {code}
        DELETE FROM PartialInvoice where dbID = '2';
        {code}


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


        It seems that the cascading delete feature is fundamentally broken.
        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. :
        {code}
             /**
          * @OneToMany(targetEntity="\persistentData\model\core\invoiceCreator\AnalogOrderInvoiceLineItem", mappedBy="partialInvoice", cascade={"persist", "remove", "detach"})
          */

         protected $analogOrderInvoiceLineItems;
         {code}

        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

        {code}
        doctrine orm:schema-tool:create --dump-sql
        {code}

        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:

        {code}
        DELETE FROM PartialInvoice where dbID = '2';
        {code}


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


        It seems that the cascading delete feature is fundamentally broken.
        beberlei Benjamin Eberlei made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        beberlei Benjamin Eberlei made changes -
        Resolution Fixed [ 1 ]
        Status Resolved [ 5 ] Reopened [ 4 ]
        beberlei Benjamin Eberlei made changes -
        Status Reopened [ 4 ] Resolved [ 5 ]
        Resolution Invalid [ 6 ]
        dalvarez Daniel Alvarez Arribas made changes -
        Resolution Invalid [ 6 ]
        Status Resolved [ 5 ] Reopened [ 4 ]
        dalvarez Daniel Alvarez Arribas made changes -
        Affects Version/s 2.1.1 [ 10153 ]
        Affects Version/s 2.0.2 [ 10116 ]
        Environment Debian Linux 5.0, MySQL 5.0 Debian Linux 6.0, MySQL 5.0.51a
        Component/s ORM [ 10012 ]
        dalvarez Daniel Alvarez Arribas made changes -
        Status Reopened [ 4 ] Resolved [ 5 ]
        Fix Version/s 2.1.1 [ 10153 ]
        Resolution Invalid [ 6 ]
        beberlei Benjamin Eberlei made changes -
        Workflow jira [ 12528 ] jira-feedback [ 14818 ]
        beberlei Benjamin Eberlei made changes -
        Workflow jira-feedback [ 14818 ] jira-feedback2 [ 16682 ]
        beberlei Benjamin Eberlei made changes -
        Workflow jira-feedback2 [ 16682 ] jira-feedback3 [ 18935 ]

          People

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

            Dates

            • Created:
              Updated:
              Resolved: